eslint-plugin-turmag-special-rules 1.0.23 → 1.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -63,13 +63,14 @@ export default [
|
|
|
63
63
|
|
|
64
64
|
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
|
|
65
65
|
|
|
66
|
-
| Name
|
|
67
|
-
|
|
|
68
|
-
| [add-vue-extension](docs/rules/add-vue-extension.md)
|
|
69
|
-
| [import-entities-by-column-or-line](docs/rules/import-entities-by-column-or-line.md)
|
|
70
|
-
| [import-right-order](docs/rules/import-right-order.md)
|
|
71
|
-
| [prefer-true-attribute-shorthand](docs/rules/prefer-true-attribute-shorthand.md)
|
|
72
|
-
| [use-shortest-alias](docs/rules/use-shortest-alias.md)
|
|
66
|
+
| Name | Description | 🔧 |
|
|
67
|
+
| :--------------------------------------------------------------------------------------- | :------------------------------------------------------------- | :- |
|
|
68
|
+
| [add-vue-extension](docs/rules/add-vue-extension.md) | Require .vue in vue files | 🔧 |
|
|
69
|
+
| [import-entities-by-column-or-line](docs/rules/import-entities-by-column-or-line.md) | Prefered column or line import | 🔧 |
|
|
70
|
+
| [import-right-order](docs/rules/import-right-order.md) | Prefered right import order | 🔧 |
|
|
71
|
+
| [prefer-true-attribute-shorthand](docs/rules/prefer-true-attribute-shorthand.md) | Require shorthand form attribute when `v-bind` value is `true` | 🔧 |
|
|
72
|
+
| [use-shortest-alias](docs/rules/use-shortest-alias.md) | There are can be used shortest alias | 🔧 |
|
|
73
|
+
| [variable-entities-by-column-or-line](docs/rules/variable-entities-by-column-or-line.md) | Prefered column or line destructuring | 🔧 |
|
|
73
74
|
|
|
74
75
|
<!-- end auto-generated rules list -->
|
|
75
76
|
|
|
@@ -34,18 +34,24 @@ module.exports = {
|
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
const getSpecifiersArr = specifiers => {
|
|
38
|
+
const specifiersArr = [];
|
|
39
|
+
specifiers.forEach(specifier => {
|
|
40
|
+
const localName = specifier.local.name;
|
|
41
|
+
|
|
42
|
+
const name = specifier.importKind === 'type' ? `type ${localName}` : localName;
|
|
43
|
+
specifiersArr.push(name);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return specifiersArr;
|
|
47
|
+
};
|
|
48
|
+
|
|
37
49
|
if(areLinesRepeated){
|
|
38
50
|
context.report({
|
|
39
51
|
node,
|
|
40
52
|
messageId: 'column',
|
|
41
53
|
fix: fixer => {
|
|
42
|
-
const specifiersArr =
|
|
43
|
-
node.specifiers.forEach(specifier => {
|
|
44
|
-
const localName = specifier.local.name;
|
|
45
|
-
|
|
46
|
-
const name = specifier.importKind === 'type' ? `type ${localName}` : localName;
|
|
47
|
-
specifiersArr.push(name);
|
|
48
|
-
});
|
|
54
|
+
const specifiersArr = getSpecifiersArr(node.specifiers);
|
|
49
55
|
|
|
50
56
|
const replaceShiftSign = '\n ';
|
|
51
57
|
return fixer.replaceText(node, `import ${isTypedNode ? 'type ' : ''}{${replaceShiftSign}${specifiersArr.join(`,${replaceShiftSign}`)},\n} from '${node.source.value}';`);
|
|
@@ -57,13 +63,7 @@ module.exports = {
|
|
|
57
63
|
node,
|
|
58
64
|
messageId: 'line',
|
|
59
65
|
fix: fixer => {
|
|
60
|
-
const specifiersArr =
|
|
61
|
-
node.specifiers.forEach(specifier => {
|
|
62
|
-
const localName = specifier.local.name;
|
|
63
|
-
|
|
64
|
-
const name = specifier.importKind === 'type' ? `type ${localName}` : localName;
|
|
65
|
-
specifiersArr.push(name);
|
|
66
|
-
});
|
|
66
|
+
const specifiersArr = getSpecifiersArr(node.specifiers);
|
|
67
67
|
|
|
68
68
|
const replaceShiftSign = ' ';
|
|
69
69
|
return fixer.replaceText(node, `import ${isTypedNode ? 'type ' : ''}{${replaceShiftSign}${specifiersArr.join(`,${replaceShiftSign}`)} } from '${node.source.value}';`);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
meta: {
|
|
3
|
+
fixable: 'code',
|
|
4
|
+
type: 'suggestion',
|
|
5
|
+
docs: { description: 'Prefered column or line destructuring' },
|
|
6
|
+
messages: {
|
|
7
|
+
column: 'Use column destructuring',
|
|
8
|
+
line: 'Use line destructuring',
|
|
9
|
+
},
|
|
10
|
+
schema: [{
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: { minProperties: { type: 'number' } },
|
|
13
|
+
}],
|
|
14
|
+
},
|
|
15
|
+
create(context) {
|
|
16
|
+
return {
|
|
17
|
+
VariableDeclaration(node) {
|
|
18
|
+
if (!node.declarations[0]) return;
|
|
19
|
+
if (node.declarations[0].id.type !== 'ObjectPattern') return;
|
|
20
|
+
if (!node.declarations[0].init) return;
|
|
21
|
+
const minProperties = context.options[0].minProperties;
|
|
22
|
+
const kind = node.kind;
|
|
23
|
+
const declaration = node.declarations[0];
|
|
24
|
+
const properties = declaration.id.properties;
|
|
25
|
+
const sourceCode = context.sourceCode;
|
|
26
|
+
const rightSideText = sourceCode.getText(declaration.init);
|
|
27
|
+
let areSmallAttributesInColumn = false;
|
|
28
|
+
let areLinesRepeated = false;
|
|
29
|
+
|
|
30
|
+
if (properties.length < minProperties) {
|
|
31
|
+
if (properties[0].loc.start.line !== properties[0].parent.loc.start.line) areSmallAttributesInColumn = true;
|
|
32
|
+
} else {
|
|
33
|
+
properties.every((property, i) => {
|
|
34
|
+
if (i === 0) return true;
|
|
35
|
+
if (property.loc.start.line === property.loc.end.line && properties[i - 1].loc.start.line === property.loc.start.line) areLinesRepeated = true;
|
|
36
|
+
else return !areLinesRepeated;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const getPropertiesArr = properties => {
|
|
41
|
+
const propertiesArr = [];
|
|
42
|
+
properties.forEach(property => {
|
|
43
|
+
if (property.type === 'RestElement') {
|
|
44
|
+
propertiesArr.push(`...${property.argument.name}`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const key = property.key.name;
|
|
48
|
+
const value = property.value.name;
|
|
49
|
+
const name = key === value ? value : `${key}: ${value}`;
|
|
50
|
+
propertiesArr.push(name);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return propertiesArr;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
if (areLinesRepeated) {
|
|
57
|
+
context.report({
|
|
58
|
+
node,
|
|
59
|
+
messageId: 'column',
|
|
60
|
+
fix: fixer => {
|
|
61
|
+
const propertiesArr = getPropertiesArr(properties);
|
|
62
|
+
const replaceShiftSign = '\n ';
|
|
63
|
+
return fixer.replaceText(node, `${kind} {${replaceShiftSign}${propertiesArr.join(`,${replaceShiftSign}`)},\n} = ${rightSideText};`);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
} else if (areSmallAttributesInColumn) {
|
|
67
|
+
context.report({
|
|
68
|
+
node,
|
|
69
|
+
messageId: 'line',
|
|
70
|
+
fix: fixer => {
|
|
71
|
+
const propertiesArr = getPropertiesArr(properties);
|
|
72
|
+
const replaceShiftSign = ' ';
|
|
73
|
+
return fixer.replaceText(node, `${kind} {${replaceShiftSign}${propertiesArr.join(`,${replaceShiftSign}`)} } = ${rightSideText};`);
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
}
|