@plumeria/eslint-plugin 0.19.1 → 0.19.3
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 +2 -2
- package/dist/index.d.ts +16 -0
- package/dist/index.js +48 -0
- package/dist/rules/no-destructure.d.ts +2 -0
- package/dist/rules/no-destructure.js +45 -0
- package/dist/rules/no-inner-call.d.ts +2 -0
- package/dist/rules/no-inner-call.js +65 -0
- package/dist/rules/no-unused-keys.d.ts +2 -0
- package/dist/rules/no-unused-keys.js +87 -0
- package/dist/rules/sort-properties.d.ts +2 -0
- package/dist/rules/sort-properties.js +114 -0
- package/dist/rules/validate-values.d.ts +2 -0
- package/dist/rules/validate-values.js +2073 -0
- package/dist/util/colorData.d.ts +2 -0
- package/dist/util/colorData.js +186 -0
- package/dist/util/place.d.ts +5 -0
- package/dist/util/place.js +230 -0
- package/dist/util/propertyGroups.d.ts +5 -0
- package/dist/util/propertyGroups.js +508 -0
- package/dist/util/unitData.d.ts +2 -0
- package/dist/util/unitData.js +37 -0
- package/dist/util/validData.d.ts +4 -0
- package/dist/util/validData.js +844 -0
- package/package.json +9 -4
- package/lib/index.d.ts +0 -19
- package/lib/index.js +0 -51
- package/lib/rules/no-destructure.js +0 -52
- package/lib/rules/no-inner-call.js +0 -69
- package/lib/rules/no-unused-keys.js +0 -111
- package/lib/rules/sort-properties.js +0 -131
- package/lib/rules/validate-values.js +0 -2479
- package/lib/util/colorData.js +0 -211
- package/lib/util/place.js +0 -306
- package/lib/util/propertyGroups.js +0 -557
- package/lib/util/unitData.js +0 -42
- package/lib/util/validData.js +0 -1052
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ The `plugin:@plumeria/recommended` config enables the following:
|
|
|
14
14
|
- `@plumeria/validate-values`: **warn**
|
|
15
15
|
|
|
16
16
|
```js
|
|
17
|
-
import plumeria from '@plumeria/eslint-plugin';
|
|
17
|
+
import { plumeria } from '@plumeria/eslint-plugin';
|
|
18
18
|
|
|
19
19
|
export default [plumeria.flatConfigs.recommended];
|
|
20
20
|
```
|
|
@@ -27,7 +27,7 @@ Disallow destructuring `css.create` and `css.props`, etc.
|
|
|
27
27
|
|
|
28
28
|
### no-inner-call
|
|
29
29
|
|
|
30
|
-
Disallow calling `css.create`,
|
|
30
|
+
Disallow calling `css.create`, etc. inside functions.
|
|
31
31
|
|
|
32
32
|
### no-unused-keys
|
|
33
33
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ESLint, Linter, Rule } from 'eslint';
|
|
2
|
+
export declare const plumeria: ESLint.Plugin & {
|
|
3
|
+
rules: {
|
|
4
|
+
"no-destructure": Rule.RuleModule;
|
|
5
|
+
"no-inner-call": Rule.RuleModule;
|
|
6
|
+
"no-unused-keys": Rule.RuleModule;
|
|
7
|
+
"sort-properties": Rule.RuleModule;
|
|
8
|
+
"validate-values": Rule.RuleModule;
|
|
9
|
+
};
|
|
10
|
+
configs: {
|
|
11
|
+
recommended: Linter.LegacyConfig;
|
|
12
|
+
};
|
|
13
|
+
flatConfigs: {
|
|
14
|
+
recommended: Linter.Config<Linter.RulesRecord>;
|
|
15
|
+
};
|
|
16
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.plumeria = void 0;
|
|
4
|
+
const no_destructure_1 = require("./rules/no-destructure");
|
|
5
|
+
const no_inner_call_js_1 = require("./rules/no-inner-call.js");
|
|
6
|
+
const no_unused_keys_1 = require("./rules/no-unused-keys");
|
|
7
|
+
const sort_properties_1 = require("./rules/sort-properties");
|
|
8
|
+
const validate_values_1 = require("./rules/validate-values");
|
|
9
|
+
const rules = {
|
|
10
|
+
'no-destructure': no_destructure_1.noDestructure,
|
|
11
|
+
'no-inner-call': no_inner_call_js_1.noInnerCall,
|
|
12
|
+
'no-unused-keys': no_unused_keys_1.noUnusedKeys,
|
|
13
|
+
'sort-properties': sort_properties_1.sortProperties,
|
|
14
|
+
'validate-values': validate_values_1.validateValues,
|
|
15
|
+
};
|
|
16
|
+
const configs = {
|
|
17
|
+
recommended: {
|
|
18
|
+
plugins: ['@plumeria'],
|
|
19
|
+
rules: {
|
|
20
|
+
'@plumeria/no-destructure': 'error',
|
|
21
|
+
'@plumeria/no-inner-call': 'error',
|
|
22
|
+
'@plumeria/no-unused-keys': 'warn',
|
|
23
|
+
'@plumeria/sort-properties': 'warn',
|
|
24
|
+
'@plumeria/validate-values': 'warn',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
const flatConfigs = {
|
|
29
|
+
recommended: {
|
|
30
|
+
plugins: {
|
|
31
|
+
'@plumeria': {
|
|
32
|
+
rules,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
rules: {
|
|
36
|
+
'@plumeria/no-destructure': 'error',
|
|
37
|
+
'@plumeria/no-inner-call': 'error',
|
|
38
|
+
'@plumeria/no-unused-keys': 'warn',
|
|
39
|
+
'@plumeria/sort-properties': 'warn',
|
|
40
|
+
'@plumeria/validate-values': 'warn',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
exports.plumeria = {
|
|
45
|
+
rules,
|
|
46
|
+
configs,
|
|
47
|
+
flatConfigs,
|
|
48
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noDestructure = void 0;
|
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
5
|
+
const createRule = utils_1.ESLintUtils.RuleCreator((name) => name);
|
|
6
|
+
exports.noDestructure = createRule({
|
|
7
|
+
name: 'no-destructure',
|
|
8
|
+
meta: {
|
|
9
|
+
type: 'problem',
|
|
10
|
+
docs: {
|
|
11
|
+
description: 'Disallow destructuring css.props and css.global',
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
noDestructure: 'Do not destructure "{{name}}" from "css". Use dot notation instead.',
|
|
15
|
+
},
|
|
16
|
+
schema: [],
|
|
17
|
+
},
|
|
18
|
+
defaultOptions: [],
|
|
19
|
+
create(context) {
|
|
20
|
+
return {
|
|
21
|
+
VariableDeclarator(node) {
|
|
22
|
+
if (node.id.type === 'ObjectPattern' &&
|
|
23
|
+
node.init &&
|
|
24
|
+
node.init.type === 'Identifier' &&
|
|
25
|
+
node.init.name === 'css') {
|
|
26
|
+
for (const prop of node.id.properties) {
|
|
27
|
+
if (prop.type === 'Property' &&
|
|
28
|
+
prop.key.type === 'Identifier' &&
|
|
29
|
+
(prop.key.name === 'create' ||
|
|
30
|
+
prop.key.name === 'props' ||
|
|
31
|
+
prop.key.name === 'keyframes' ||
|
|
32
|
+
prop.key.name === 'viewTransition' ||
|
|
33
|
+
prop.key.name.startsWith('define'))) {
|
|
34
|
+
context.report({
|
|
35
|
+
node: prop,
|
|
36
|
+
messageId: 'noDestructure',
|
|
37
|
+
data: { name: prop.key.name },
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noInnerCall = void 0;
|
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
5
|
+
const createRule = utils_1.ESLintUtils.RuleCreator((name) => name);
|
|
6
|
+
exports.noInnerCall = createRule({
|
|
7
|
+
name: 'no-inner-call',
|
|
8
|
+
meta: {
|
|
9
|
+
type: 'problem',
|
|
10
|
+
docs: {
|
|
11
|
+
description: 'An error occurs if a specific call is made within a function',
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
noInnerCall: 'Do not use {{name}} inside functions',
|
|
15
|
+
},
|
|
16
|
+
schema: [],
|
|
17
|
+
},
|
|
18
|
+
defaultOptions: [],
|
|
19
|
+
create(context) {
|
|
20
|
+
let functionDepth = 0;
|
|
21
|
+
return {
|
|
22
|
+
FunctionDeclaration() {
|
|
23
|
+
functionDepth++;
|
|
24
|
+
},
|
|
25
|
+
FunctionExpression() {
|
|
26
|
+
functionDepth++;
|
|
27
|
+
},
|
|
28
|
+
ArrowFunctionExpression() {
|
|
29
|
+
functionDepth++;
|
|
30
|
+
},
|
|
31
|
+
'FunctionDeclaration:exit'() {
|
|
32
|
+
functionDepth--;
|
|
33
|
+
},
|
|
34
|
+
'FunctionExpression:exit'() {
|
|
35
|
+
functionDepth--;
|
|
36
|
+
},
|
|
37
|
+
'ArrowFunctionExpression:exit'() {
|
|
38
|
+
functionDepth--;
|
|
39
|
+
},
|
|
40
|
+
CallExpression(node) {
|
|
41
|
+
if (functionDepth > 0) {
|
|
42
|
+
if (node.callee.type === 'MemberExpression' &&
|
|
43
|
+
'name' in node.callee.object &&
|
|
44
|
+
'name' in node.callee.property) {
|
|
45
|
+
const objectName = node.callee.object.name;
|
|
46
|
+
const propertyName = node.callee.property.name;
|
|
47
|
+
if (objectName === 'css') {
|
|
48
|
+
const fullName = `${objectName}.${propertyName}`;
|
|
49
|
+
if (propertyName === 'create' ||
|
|
50
|
+
propertyName === 'keyframes' ||
|
|
51
|
+
propertyName === 'viewTransition' ||
|
|
52
|
+
propertyName.startsWith('define')) {
|
|
53
|
+
context.report({
|
|
54
|
+
node,
|
|
55
|
+
messageId: 'noInnerCall',
|
|
56
|
+
data: { name: fullName },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noUnusedKeys = void 0;
|
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
5
|
+
const createRule = utils_1.ESLintUtils.RuleCreator((name) => name);
|
|
6
|
+
function getFilename(context) {
|
|
7
|
+
return context.getFilename ? context.getFilename() : context.filename;
|
|
8
|
+
}
|
|
9
|
+
exports.noUnusedKeys = createRule({
|
|
10
|
+
name: 'no-unused-keys',
|
|
11
|
+
meta: {
|
|
12
|
+
type: 'problem',
|
|
13
|
+
docs: {
|
|
14
|
+
description: 'Detect unused object keys if they are not referenced anywhere',
|
|
15
|
+
},
|
|
16
|
+
messages: {
|
|
17
|
+
unusedKey: "The key '{{ key }}' is defined but never referenced anywhere.",
|
|
18
|
+
},
|
|
19
|
+
schema: [],
|
|
20
|
+
},
|
|
21
|
+
defaultOptions: [],
|
|
22
|
+
create(context) {
|
|
23
|
+
const filename = getFilename(context);
|
|
24
|
+
if (filename.endsWith('.ts')) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
const parserServices = context.parserServices;
|
|
28
|
+
const checker = parserServices?.program?.getTypeChecker();
|
|
29
|
+
const definedKeys = new Map();
|
|
30
|
+
const referencedKeys = new Set();
|
|
31
|
+
return {
|
|
32
|
+
CallExpression(node) {
|
|
33
|
+
if (node.callee.type === 'MemberExpression' &&
|
|
34
|
+
'name' in node.callee.object &&
|
|
35
|
+
'name' in node.callee.property &&
|
|
36
|
+
node.callee.object.name === 'css' &&
|
|
37
|
+
node.callee.property.name === 'create') {
|
|
38
|
+
const arg = node.arguments[0];
|
|
39
|
+
if (arg &&
|
|
40
|
+
arg.type === 'ObjectExpression' &&
|
|
41
|
+
node.parent.type === 'VariableDeclarator' &&
|
|
42
|
+
'name' in node.parent.id) {
|
|
43
|
+
const variableName = node.parent.id.name;
|
|
44
|
+
const keyMap = new Map();
|
|
45
|
+
arg.properties.forEach((prop) => {
|
|
46
|
+
if (prop.type === 'Property' &&
|
|
47
|
+
prop.key &&
|
|
48
|
+
prop.key.type === 'Identifier' &&
|
|
49
|
+
prop.value.type === 'ObjectExpression') {
|
|
50
|
+
keyMap.set(prop.key.name, prop.key);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
definedKeys.set(variableName, keyMap);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
MemberExpression(node) {
|
|
58
|
+
if (node.object.type === 'Identifier' &&
|
|
59
|
+
node.property.type === 'Identifier') {
|
|
60
|
+
const normalKey = `${node.object.name}.${node.property.name}`;
|
|
61
|
+
referencedKeys.add(normalKey);
|
|
62
|
+
if (parserServices && checker) {
|
|
63
|
+
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
|
|
64
|
+
const symbol = checker.getSymbolAtLocation(tsNode);
|
|
65
|
+
if (symbol) {
|
|
66
|
+
referencedKeys.add(normalKey);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
'Program:exit'() {
|
|
72
|
+
definedKeys.forEach((keyMap, variableName) => {
|
|
73
|
+
keyMap.forEach((keyNode, keyName) => {
|
|
74
|
+
const normalKey = `${variableName}.${keyName}`;
|
|
75
|
+
if (!referencedKeys.has(normalKey)) {
|
|
76
|
+
context.report({
|
|
77
|
+
node: keyNode,
|
|
78
|
+
messageId: 'unusedKey',
|
|
79
|
+
data: { key: keyName },
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortProperties = void 0;
|
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
5
|
+
const propertyGroups_1 = require("../util/propertyGroups");
|
|
6
|
+
const createRule = utils_1.ESLintUtils.RuleCreator((name) => name);
|
|
7
|
+
function getSourceCode(context) {
|
|
8
|
+
return context.getSourceCode ? context.getSourceCode() : context.sourceCode;
|
|
9
|
+
}
|
|
10
|
+
function getPropertyName(property) {
|
|
11
|
+
if (property.key.type === 'Literal' && Array.isArray(property.key.value)) {
|
|
12
|
+
return property.key.value;
|
|
13
|
+
}
|
|
14
|
+
if (property.key.type === 'Identifier') {
|
|
15
|
+
return property.key.name;
|
|
16
|
+
}
|
|
17
|
+
if (property.key.type === 'Literal') {
|
|
18
|
+
return String(property.key.value);
|
|
19
|
+
}
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
function getPropertyIndex(property, isTopLevel = false) {
|
|
23
|
+
const name = getPropertyName(property);
|
|
24
|
+
if (Array.isArray(name)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if (isTopLevel &&
|
|
28
|
+
(property.key.type !== 'Identifier' ||
|
|
29
|
+
(typeof name === 'string' &&
|
|
30
|
+
(name.startsWith('&') || name.startsWith(':') || name.startsWith('@'))))) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
let lastGroupIndex = 0;
|
|
34
|
+
let maxPropIndex = 0;
|
|
35
|
+
for (let i = 0; i < propertyGroups_1.propertyGroups.length; i++) {
|
|
36
|
+
const group = propertyGroups_1.propertyGroups[i];
|
|
37
|
+
const propIndex = group.properties.indexOf(name);
|
|
38
|
+
if (propIndex !== -1) {
|
|
39
|
+
return i * 1000 + propIndex;
|
|
40
|
+
}
|
|
41
|
+
lastGroupIndex = i;
|
|
42
|
+
maxPropIndex = Math.max(maxPropIndex, group.properties.length);
|
|
43
|
+
}
|
|
44
|
+
if (typeof name === 'string') {
|
|
45
|
+
if (name.startsWith('&'))
|
|
46
|
+
return (propertyGroups_1.propertyGroups.length + 1) * 1000;
|
|
47
|
+
if (name.includes(':'))
|
|
48
|
+
return (propertyGroups_1.propertyGroups.length + 2) * 1000;
|
|
49
|
+
if (name.includes('@media'))
|
|
50
|
+
return (propertyGroups_1.propertyGroups.length + 3) * 1000;
|
|
51
|
+
}
|
|
52
|
+
return lastGroupIndex * 1000 + maxPropIndex + 1;
|
|
53
|
+
}
|
|
54
|
+
exports.sortProperties = createRule({
|
|
55
|
+
name: 'sort-properties',
|
|
56
|
+
meta: {
|
|
57
|
+
type: 'suggestion',
|
|
58
|
+
docs: {
|
|
59
|
+
description: 'Sort CSS properties keeping original order for specific keys',
|
|
60
|
+
},
|
|
61
|
+
fixable: 'code',
|
|
62
|
+
schema: [],
|
|
63
|
+
messages: {
|
|
64
|
+
sortProperties: 'Property "{{property}}" should be at position {{position}}',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
defaultOptions: [],
|
|
68
|
+
create(context) {
|
|
69
|
+
return {
|
|
70
|
+
ObjectExpression(node) {
|
|
71
|
+
const sourceCode = getSourceCode(context);
|
|
72
|
+
const isTopLevel = !node.parent || node.parent.type !== 'Property';
|
|
73
|
+
const properties = node.properties.filter((prop) => 'key' in prop && !!prop.key);
|
|
74
|
+
const sorted = [...properties].sort((a, b) => {
|
|
75
|
+
const indexA = getPropertyIndex(a, isTopLevel);
|
|
76
|
+
const indexB = getPropertyIndex(b, isTopLevel);
|
|
77
|
+
return indexA === null || indexB === null ? 0 : indexA - indexB;
|
|
78
|
+
});
|
|
79
|
+
const misordered = properties.filter((prop, i) => prop !== sorted[i]);
|
|
80
|
+
if (misordered.length === 0)
|
|
81
|
+
return;
|
|
82
|
+
const match = sourceCode.getText(node).match(/^{\s*\n(\s*)/);
|
|
83
|
+
const indent = match ? match[1] : '';
|
|
84
|
+
const lineEnding = match ? '\n' : ' ';
|
|
85
|
+
misordered.forEach((prop) => {
|
|
86
|
+
context.report({
|
|
87
|
+
node: prop,
|
|
88
|
+
messageId: 'sortProperties',
|
|
89
|
+
data: {
|
|
90
|
+
position: sorted.indexOf(prop) + 1,
|
|
91
|
+
property: getPropertyName(prop),
|
|
92
|
+
},
|
|
93
|
+
fix(fixer) {
|
|
94
|
+
const newText = sorted
|
|
95
|
+
.map((p) => {
|
|
96
|
+
const propName = getPropertyName(p);
|
|
97
|
+
if (Array.isArray(propName)) {
|
|
98
|
+
const arrayKey = sourceCode.getText(p.key);
|
|
99
|
+
const arrayContent = p.value.properties
|
|
100
|
+
.map((inner) => `${indent} ${sourceCode.getText(inner)}`)
|
|
101
|
+
.join(`,${lineEnding}`);
|
|
102
|
+
return `${indent}${arrayKey}: {\n${arrayContent}\n${indent}}`;
|
|
103
|
+
}
|
|
104
|
+
return `${indent}${sourceCode.getText(p)}`;
|
|
105
|
+
})
|
|
106
|
+
.join(`,${lineEnding}`);
|
|
107
|
+
return fixer.replaceTextRange([node.range[0] + 1, node.range[1] - 1], `${lineEnding}${newText}${lineEnding}`);
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
});
|