Skip to content

Commit

Permalink
Remove disableFix option from rules
Browse files Browse the repository at this point in the history
  • Loading branch information
hudochenkov committed Oct 16, 2021
1 parent 6e7330a commit 50f823f
Show file tree
Hide file tree
Showing 13 changed files with 12 additions and 352 deletions.
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,7 @@ Automatic sorting has some limitations that are described for every rule, if any

CSS-in-JS styles with template interpolation [could be ignored by autofixing](https://github.com/hudochenkov/postcss-sorting#css-in-js) to avoid style corruption.

Autofixing is enabled by default if it's enabled in stylelint's configuration file. It can be disabled on a per rule basis using the secondary option `disableFix: true`. Here's an example:

```json
"rules": {
"order/order": [
[
"custom-properties",
"declarations"
],
{
"disableFix": true
}
]
}
```

Less may work but isn't officially supported.
Autofixing in Less syntax may work but isn't officially supported.

## Example configs

Expand Down
9 changes: 0 additions & 9 deletions rules/order/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Specify the order of content within declaration blocks.
* [Extended rule objects](#extended-rule-objects)
* Optional secondary options
* [`unspecified`](#unspecified)
* [`disableFix`](#disablefix)
* [Autofixing caveats](#autofixing-caveats)
* [Examples](#examples)

Expand Down Expand Up @@ -180,7 +179,6 @@ Matches all rules with selector matching pattern:
```ts
type SecondaryOptions = {
unspecified?: "top" | "bottom" | "ignore",
disableFix?: boolean
};
```

Expand All @@ -193,13 +191,6 @@ Default behavior is the same as `"ignore"`: an unspecified element can appear be

With `"top"`, unspecified elements are expected _before_ any specified properties. With `"bottom"`, unspecified properties are expected _after_ any specified properties.

### `disableFix`

Value type: `boolean`.<br>
Default value: none.

Disable autofixing. Autofixing is enabled by default if it's enabled in stylelint configuration.

## Autofixing caveats

Keyword `less-mixins` aren't supported.
Expand Down
6 changes: 1 addition & 5 deletions rules/order/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const stylelint = require('stylelint');
const { getContainingNode, isRuleWithNodes } = require('../../utils');
const { isBoolean } = require('../../utils/validateType');
const checkNode = require('./checkNode');
const createOrderInfo = require('./createOrderInfo');
const validatePrimaryOption = require('./validatePrimaryOption');
Expand All @@ -20,7 +19,6 @@ function rule(primaryOption, options = {}, context = {}) {
actual: options,
possible: {
unspecified: ['top', 'bottom', 'ignore'],
disableFix: isBoolean,
},
optional: true,
}
Expand All @@ -30,8 +28,6 @@ function rule(primaryOption, options = {}, context = {}) {
return;
}

let disableFix = options.disableFix || false;
let isFixEnabled = context.fix && !disableFix;
let unspecified = options.unspecified || 'ignore';
let orderInfo = createOrderInfo(primaryOption);

Expand All @@ -51,7 +47,7 @@ function rule(primaryOption, options = {}, context = {}) {
if (isRuleWithNodes(node)) {
checkNode({
node,
isFixEnabled,
isFixEnabled: context.fix,
orderInfo,
primaryOption,
result,
Expand Down
62 changes: 0 additions & 62 deletions rules/order/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1253,68 +1253,6 @@ testRule({
],
});

testRule({
ruleName,
config: [
['custom-properties', 'dollar-variables', 'declarations', 'rules', 'at-rules'],
{
disableFix: true,
},
],
fix: true,

accept: [
{
code: `
a {
--width: 10px;
$height: 20px;
display: none;
span {}
@media (min-width: 100px) {}
}
`,
},
{
code: `
a {
$height: 20px;
@media (min-width: 100px) {}
}
`,
},
],

reject: [
{
code: `
a {
display: none;
--width: 10px;
}
`,
unfixable: true,
message: messages.expected('custom property', 'declaration'),
description: `shouldn't apply fixes`,
},
{
code: `
a {
--width: 10px;
display: none;
$height: 20px;
}
`,
unfixable: true,
message: messages.expected('$-variable', 'declaration'),
description: `shouldn't apply fixes`,
},
],
});

testRule({
ruleName,
config: [['custom-properties']],
Expand Down
24 changes: 0 additions & 24 deletions rules/order/tests/validate-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,27 +322,3 @@ testConfig({
],
message: `Invalid option "[{"type":"rule","selector":null,"name":"Element"}]" for rule ${ruleName}`,
});

testConfig({
ruleName,
description: 'disableFix true',
valid: true,
config: [
['custom-properties', 'dollar-variables'],
{
disableFix: true,
},
],
});

testConfig({
ruleName,
description: 'disableFix false',
valid: true,
config: [
['custom-properties', 'dollar-variables'],
{
disableFix: false,
},
],
});
18 changes: 0 additions & 18 deletions rules/properties-alphabetical-order/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,3 @@ a {
transform: scale(1);
}
```

## Optional secondary options

### `disableFix`

Value type: `boolean`.<br>
Default value: none.

Disable autofixing. Autofixing is enabled by default if it's enabled in stylelint configuration.

```json
{
"order/properties-alphabetical-order": [
true,
{ "disableFix": true }
]
}
```
25 changes: 6 additions & 19 deletions rules/properties-alphabetical-order/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,17 @@ let messages = stylelint.utils.ruleMessages(ruleName, {
expected: (first, second) => `Expected ${first} to come before ${second}`,
});

function rule(actual, options = {}, context = {}) {
function rule(actual, options, context = {}) {
return function ruleBody(root, result) {
let validOptions = stylelint.utils.validateOptions(
result,
ruleName,
{
actual,
possible: Boolean,
},
{
actual: options,
possible: {
disableFix: Boolean,
},
optional: true,
}
);
let validOptions = stylelint.utils.validateOptions(result, ruleName, {
actual,
possible: Boolean,
});

if (!validOptions) {
return;
}

let disableFix = options.disableFix || false;

let processedParents = [];

root.walk(function processRulesAndAtrules(input) {
Expand All @@ -46,7 +33,7 @@ function rule(actual, options = {}, context = {}) {
processedParents.push(node);

if (isRuleWithNodes(node)) {
if (context.fix && !disableFix) {
if (context.fix) {
sortNodeProperties(node, { order: 'alphabetical' });
} else {
checkNode(node, result, ruleName, messages);
Expand Down
35 changes: 0 additions & 35 deletions rules/properties-alphabetical-order/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,41 +134,6 @@ testRule({
],
});

testRule({
ruleName,
config: [
true,
{
disableFix: true,
},
],
fix: true,

accept: [
{
code: 'a { color: pink; top: 0; }',
},
{
code: 'a { border: 1px solid pink; border-left-width: 0; }',
},
],

reject: [
{
code: 'a { top: 0; color: pink; }',
unfixable: true,
message: messages.expected('color', 'top'),
description: `shouldn't apply fixes`,
},
{
code: 'a { color: pink; transform: scale(1); top: 0; }',
unfixable: true,
message: messages.expected('top', 'transform'),
description: `shouldn't apply fixes`,
},
],
});

testRule({
ruleName,
config: [true],
Expand Down
22 changes: 2 additions & 20 deletions rules/properties-order/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ This rule ignores variables (`$sass`, `@less`, `--custom-property`).
* [`unspecified`](#unspecified)
* [`emptyLineBeforeUnspecified`](#emptyLineBeforeUnspecified)
* [`emptyLineMinimumPropertyThreshold`](#emptylineminimumpropertythreshold)
* [`disableFix`](#disablefix)
* [Autofixing caveats](#autofixing-caveats)

## Options
Expand Down Expand Up @@ -49,9 +48,9 @@ Array of unprefixed property names or group objects. Within an order array, you
If `emptyLineBefore` specified, regardless of it's value, the first property in a rule would be forced to not have an empty line before it.

For `threshold`, refer to the [`emptyLineMinimumPropertyThreshold` documentation](#emptylineminimumpropertythreshold-number).

If this option is not working as expected, make sure you don't have `declaration-empty-line-before` configured in a conflicting way in your stylelint config or config you're extending (e. g. [`stylelint-config-standard`](https://github.com/stylelint/stylelint-config-standard)).


* `noEmptyLineBetween`: If `true`, properties within group should not have empty lines between them.
* `groupName`: An optional name for the group. This will be used in error messages.
Expand Down Expand Up @@ -511,7 +510,6 @@ type SecondaryOptions = {
unspecified?: "top" | "bottom" | "bottomAlphabetical" | "ignore",
emptyLineBeforeUnspecified?: "always" | "never" | "threshold",
emptyLineMinimumPropertyThreshold?: number,
disableFix?: boolean
};
```

Expand Down Expand Up @@ -863,22 +861,6 @@ a {
}
```

### `disableFix`

Value type: `boolean`.<br>
Default value: none.

Disable autofixing. Autofixing is enabled by default if it's enabled in stylelint configuration.

```json
{
"order/properties-order": [
["color", "background"],
{ "disableFix": true }
]
}
```

## Autofixing caveats

Properties will be grouped together, if other node types between them (except comments). They will be grouped with the first found property. E.g.:
Expand Down
5 changes: 2 additions & 3 deletions rules/properties-order/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const stylelint = require('stylelint');
const { getContainingNode, isRuleWithNodes } = require('../../utils');
const { isBoolean, isNumber } = require('../../utils/validateType');
const { isNumber } = require('../../utils/validateType');
const checkNodeForOrder = require('./checkNodeForOrder');
const checkNodeForEmptyLines = require('./checkNodeForEmptyLines');
const createOrderInfo = require('./createOrderInfo');
Expand All @@ -23,7 +23,6 @@ function rule(primaryOption, options = {}, context = {}) {
possible: {
unspecified: ['top', 'bottom', 'ignore', 'bottomAlphabetical'],
emptyLineBeforeUnspecified: ['always', 'never', 'threshold'],
disableFix: isBoolean,
emptyLineMinimumPropertyThreshold: isNumber,
},
optional: true,
Expand All @@ -34,7 +33,7 @@ function rule(primaryOption, options = {}, context = {}) {
return;
}

let isFixEnabled = context.fix && !options.disableFix;
let isFixEnabled = context.fix;
let expectedOrder = createOrderInfo(primaryOption);

let processedParents = [];
Expand Down
Loading

0 comments on commit 50f823f

Please sign in to comment.