@plumeria/eslint-plugin 0.2.1 → 0.2.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/lib/index.d.ts +1 -0
- package/lib/index.js +4 -0
- package/lib/rules/no-destructure.js +54 -0
- package/lib/rules/no-inner-call.js +1 -2
- package/package.json +1 -1
- package/readme.md +5 -0
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const noDestructure = require('./rules/no-destructure.js');
|
|
3
4
|
const noInnerCall = require('./rules/no-inner-call.js');
|
|
4
5
|
const noUnusedKeys = require('./rules/no-unused-keys.js');
|
|
5
6
|
const sortProperties = require('./rules/sort-properties.js');
|
|
6
7
|
const validateValues = require('./rules/validate-values.js');
|
|
7
8
|
|
|
8
9
|
const rules = {
|
|
10
|
+
'no-destructure': noDestructure,
|
|
9
11
|
'no-inner-call': noInnerCall,
|
|
10
12
|
'no-unused-keys': noUnusedKeys,
|
|
11
13
|
'sort-properties': sortProperties,
|
|
@@ -16,6 +18,7 @@ const configs = {
|
|
|
16
18
|
recommended: {
|
|
17
19
|
plugins: ['@plumeria'],
|
|
18
20
|
rules: {
|
|
21
|
+
'@plumeria/no-destructure': 'error',
|
|
19
22
|
'@plumeria/no-inner-call': 'error',
|
|
20
23
|
'@plumeria/no-unused-keys': 'warn',
|
|
21
24
|
'@plumeria/sort-properties': 'warn',
|
|
@@ -32,6 +35,7 @@ const flatConfigs = {
|
|
|
32
35
|
},
|
|
33
36
|
},
|
|
34
37
|
rules: {
|
|
38
|
+
'@plumeria/no-destructure': 'error',
|
|
35
39
|
'@plumeria/no-inner-call': 'error',
|
|
36
40
|
'@plumeria/no-unused-keys': 'warn',
|
|
37
41
|
'@plumeria/sort-properties': 'warn',
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Restrict destructure css.create and css.global
|
|
3
|
+
* Compatible with eslint 8 and below or 9 and above
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
9
|
+
module.exports = {
|
|
10
|
+
meta: {
|
|
11
|
+
type: 'problem',
|
|
12
|
+
docs: {
|
|
13
|
+
description: 'Disallow destructuring css.create and css.global',
|
|
14
|
+
recommended: true,
|
|
15
|
+
},
|
|
16
|
+
messages: {
|
|
17
|
+
noDestructure:
|
|
18
|
+
'Do not destructure "{{name}}" from "css". Use dot notation instead.',
|
|
19
|
+
},
|
|
20
|
+
schema: [],
|
|
21
|
+
},
|
|
22
|
+
create(context) {
|
|
23
|
+
const isCssIdentifier = (node) =>
|
|
24
|
+
node.type === 'Identifier' && node.name === 'css';
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
VariableDeclarator(node) {
|
|
28
|
+
if (
|
|
29
|
+
node.id.type === 'ObjectPattern' &&
|
|
30
|
+
node.init &&
|
|
31
|
+
isCssIdentifier(node.init)
|
|
32
|
+
) {
|
|
33
|
+
const forbiddenKeys = ['create', 'global'];
|
|
34
|
+
const violated = node.id.properties.filter(
|
|
35
|
+
(prop) =>
|
|
36
|
+
prop.type === 'Property' &&
|
|
37
|
+
prop.key.type === 'Identifier' &&
|
|
38
|
+
forbiddenKeys.includes(prop.key.name),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if (violated.length > 0) {
|
|
42
|
+
for (const prop of violated) {
|
|
43
|
+
context.report({
|
|
44
|
+
node: prop,
|
|
45
|
+
messageId: 'noDestructure',
|
|
46
|
+
data: { name: prop.key.name },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
};
|
|
@@ -52,8 +52,7 @@ module.exports = {
|
|
|
52
52
|
propertyName === 'create' ||
|
|
53
53
|
propertyName === 'global' ||
|
|
54
54
|
propertyName === 'keyframes' ||
|
|
55
|
-
propertyName
|
|
56
|
-
propertyName === 'defineTheme'
|
|
55
|
+
propertyName.startsWith('define')
|
|
57
56
|
) {
|
|
58
57
|
context.report({
|
|
59
58
|
node,
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -7,6 +7,7 @@ Below are the available rules and the recommended configuration.
|
|
|
7
7
|
|
|
8
8
|
The `plugin:@plumeria/recommended` config enables the following:
|
|
9
9
|
|
|
10
|
+
- `@plumeria/no-destructure`: **error**
|
|
10
11
|
- `@plumeria/no-inner-call`: **error**
|
|
11
12
|
- `@plumeria/no-unused-keys`: **warn**
|
|
12
13
|
- `@plumeria/sort-properties`: **warn**
|
|
@@ -20,6 +21,10 @@ export default [plumeria.flatConfigs.recommended];
|
|
|
20
21
|
|
|
21
22
|
## Rules
|
|
22
23
|
|
|
24
|
+
### no-destructure
|
|
25
|
+
|
|
26
|
+
Disallow destructuring `css.create` and `css.global`.
|
|
27
|
+
|
|
23
28
|
### no-inner-call
|
|
24
29
|
|
|
25
30
|
Disallow calling `css.create`, `css.global`, etc. inside functions.
|