@plumeria/eslint-plugin 0.19.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/eslint-plugin",
3
- "version": "0.19.2",
3
+ "version": "0.19.3",
4
4
  "description": "Plumeria ESLint plugin",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,15 +8,20 @@
8
8
  "directory": "packages/eslint-plugin"
9
9
  },
10
10
  "license": "MIT",
11
- "main": "lib/index.js",
12
- "types": "lib/index.d.ts",
11
+ "main": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
13
  "files": [
14
- "lib/"
14
+ "dist/"
15
15
  ],
16
16
  "devDependencies": {
17
+ "@typescript-eslint/utils": "^8.44.1",
17
18
  "eslint": "^9.15.0"
18
19
  },
19
20
  "publishConfig": {
20
21
  "access": "public"
22
+ },
23
+ "scripts": {
24
+ "build": "rimraf dist && pnpm cjs",
25
+ "cjs": "tsc --project tsconfig.cjs.json"
21
26
  }
22
27
  }
package/lib/index.d.ts DELETED
@@ -1,19 +0,0 @@
1
- import { ESLint, Linter, Rule } from 'eslint';
2
-
3
- declare const plugin: ESLint.Plugin & {
4
- rules: {
5
- 'no-destructure': Rule.RuleModule;
6
- 'no-inner-call': Rule.RuleModule;
7
- 'no-unused-keys': Rule.RuleModule;
8
- 'sort-properties': Rule.RuleModule;
9
- 'validate-values': Rule.RuleModule;
10
- };
11
- configs: {
12
- recommended: Linter.LegacyConfig;
13
- };
14
- flatConfigs: {
15
- recommended: Linter.Config<Linter.RulesRecord>;
16
- };
17
- };
18
-
19
- export = plugin;
package/lib/index.js DELETED
@@ -1,51 +0,0 @@
1
- 'use strict';
2
-
3
- const noDestructure = require('./rules/no-destructure.js');
4
- const noInnerCall = require('./rules/no-inner-call.js');
5
- const noUnusedKeys = require('./rules/no-unused-keys.js');
6
- const sortProperties = require('./rules/sort-properties.js');
7
- const validateValues = require('./rules/validate-values.js');
8
-
9
- const rules = {
10
- 'no-destructure': noDestructure,
11
- 'no-inner-call': noInnerCall,
12
- 'no-unused-keys': noUnusedKeys,
13
- 'sort-properties': sortProperties,
14
- 'validate-values': validateValues,
15
- };
16
-
17
- const configs = {
18
- recommended: {
19
- plugins: ['@plumeria'],
20
- rules: {
21
- '@plumeria/no-destructure': 'error',
22
- '@plumeria/no-inner-call': 'error',
23
- '@plumeria/no-unused-keys': 'warn',
24
- '@plumeria/sort-properties': 'warn',
25
- '@plumeria/validate-values': 'warn',
26
- },
27
- },
28
- };
29
-
30
- const flatConfigs = {
31
- recommended: {
32
- plugins: {
33
- '@plumeria': {
34
- rules,
35
- },
36
- },
37
- rules: {
38
- '@plumeria/no-destructure': 'error',
39
- '@plumeria/no-inner-call': 'error',
40
- '@plumeria/no-unused-keys': 'warn',
41
- '@plumeria/sort-properties': 'warn',
42
- '@plumeria/validate-values': 'warn',
43
- },
44
- },
45
- };
46
-
47
- module.exports = {
48
- rules,
49
- configs,
50
- flatConfigs,
51
- };
@@ -1,52 +0,0 @@
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.props 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
- return {
24
- VariableDeclarator(node) {
25
- if (
26
- node.id.type === 'ObjectPattern' &&
27
- node.init &&
28
- node.init.type === 'Identifier' &&
29
- node.init.name === 'css'
30
- ) {
31
- for (const prop of node.id.properties) {
32
- if (
33
- prop.type === 'Property' &&
34
- prop.key.type === 'Identifier' &&
35
- (prop.key.name === 'create' ||
36
- prop.key.name === 'props' ||
37
- prop.key.name === 'keyframes' ||
38
- prop.key.name === 'viewTransition' ||
39
- prop.key.name.startsWith('define'))
40
- ) {
41
- context.report({
42
- node: prop,
43
- messageId: 'noDestructure',
44
- data: { name: prop.key.name },
45
- });
46
- }
47
- }
48
- }
49
- },
50
- };
51
- },
52
- };
@@ -1,69 +0,0 @@
1
- /**
2
- * @fileoverview Restrict calls inside a function
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:
14
- 'An error occurs if a specific call is made within a function',
15
- recommended: true,
16
- },
17
- messages: {
18
- noInnerCall: 'Do not use {{name}} inside functions',
19
- },
20
- },
21
- create(context) {
22
- let functionDepth = 0;
23
-
24
- return {
25
- FunctionDeclaration() {
26
- functionDepth++;
27
- },
28
- FunctionExpression() {
29
- functionDepth++;
30
- },
31
- ArrowFunctionExpression() {
32
- functionDepth++;
33
- },
34
- 'FunctionDeclaration:exit'() {
35
- functionDepth--;
36
- },
37
- 'FunctionExpression:exit'() {
38
- functionDepth--;
39
- },
40
- 'ArrowFunctionExpression:exit'() {
41
- functionDepth--;
42
- },
43
- CallExpression(node) {
44
- if (functionDepth > 0) {
45
- if (node.callee.type === 'MemberExpression') {
46
- const objectName = node.callee.object.name;
47
- const propertyName = node.callee.property.name;
48
-
49
- if (objectName === 'css') {
50
- const fullName = `${objectName}.${propertyName}`;
51
- if (
52
- propertyName === 'create' ||
53
- propertyName === 'keyframes' ||
54
- propertyName === 'viewTransition' ||
55
- propertyName.startsWith('define')
56
- ) {
57
- context.report({
58
- node,
59
- messageId: 'noInnerCall',
60
- data: { name: fullName },
61
- });
62
- }
63
- }
64
- }
65
- }
66
- },
67
- };
68
- },
69
- };
@@ -1,111 +0,0 @@
1
- /**
2
- * @fileoverview Warns about unused keys in objects inside functions
3
- * Compatible with eslint 8 and below or 9 and above
4
- */
5
-
6
- 'use strict';
7
-
8
- /**
9
- * @param {import('eslint').Rule.RuleContext} context
10
- * @returns {import('eslint').Filename}
11
- */
12
- function getFilename(context) {
13
- return context.getFilename ? context.getFilename() : context.filename;
14
- }
15
-
16
- /** @type {import('eslint').Rule.RuleModule} */
17
- module.exports = {
18
- meta: {
19
- type: 'problem',
20
- docs: {
21
- description:
22
- 'Detect unused object keys if they are not referenced anywhere',
23
- recommended: true,
24
- },
25
- messages: {
26
- unusedKey:
27
- "The key '{{ key }}' is defined but never referenced anywhere.",
28
- },
29
- },
30
-
31
- create(context) {
32
- const filename = getFilename(context);
33
- if (filename.endsWith('.ts')) {
34
- return {};
35
- }
36
- const parserServices = context.parserServices;
37
- const checker = parserServices?.program?.getTypeChecker();
38
- const definedKeys = new Map();
39
- const referencedKeys = new Set();
40
-
41
- return {
42
- CallExpression(node) {
43
- if (
44
- node.callee.type === 'MemberExpression' &&
45
- node.callee.object.name === 'css' &&
46
- node.callee.property.name === 'create'
47
- ) {
48
- const arg = node.arguments[0];
49
- if (
50
- arg &&
51
- arg.type === 'ObjectExpression' &&
52
- node.parent.type === 'VariableDeclarator'
53
- ) {
54
- const variableName = node.parent.id.name;
55
- const keyMap = new Map();
56
-
57
- arg.properties.forEach((prop) => {
58
- if (
59
- prop.key &&
60
- prop.key.type === 'Identifier' &&
61
- prop.value.type === 'ObjectExpression'
62
- ) {
63
- keyMap.set(prop.key.name, prop.key);
64
- }
65
- });
66
-
67
- definedKeys.set(variableName, keyMap);
68
- }
69
- }
70
- },
71
- MemberExpression(node) {
72
- if (
73
- node.object.type === 'Identifier' &&
74
- node.property.type === 'Identifier'
75
- ) {
76
- const normalKey = `${node.object.name}.${node.property.name}`;
77
- const dollerKey = `${node.object.name}.$${node.property.name}`;
78
- referencedKeys.add(normalKey);
79
- referencedKeys.add(dollerKey);
80
-
81
- if (parserServices && checker) {
82
- const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
83
- const symbol = checker.getSymbolAtLocation(tsNode);
84
- if (symbol) {
85
- referencedKeys.add(normalKey);
86
- referencedKeys.add(dollerKey);
87
- }
88
- }
89
- }
90
- },
91
- 'Program:exit'() {
92
- definedKeys.forEach((keyMap, variableName) => {
93
- keyMap.forEach((keyNode, keyName) => {
94
- const normalKey = `${variableName}.${keyName}`;
95
- const dollerKey = `${variableName}.$${keyName}`;
96
- if (
97
- !referencedKeys.has(normalKey) &&
98
- !referencedKeys.has(dollerKey)
99
- ) {
100
- context.report({
101
- node: keyNode,
102
- messageId: 'unusedKey',
103
- data: { key: keyName },
104
- });
105
- }
106
- });
107
- });
108
- },
109
- };
110
- },
111
- };
@@ -1,131 +0,0 @@
1
- /**
2
- * @fileoverview CSS properties recess base reorder fix feature
3
- * Compatible with eslint 8 and below or 9 and above
4
- */
5
-
6
- 'use strict';
7
-
8
- const propertyGroups = require('../util/propertyGroups');
9
-
10
- /**
11
- * @param {import('eslint').Rule.RuleContext} context
12
- * @returns {import('eslint').SourceCode}
13
- */
14
- function getSourceCode(context) {
15
- return context.getSourceCode ? context.getSourceCode() : context.sourceCode;
16
- }
17
-
18
- function getPropertyName(property) {
19
- if (property.key.type === 'Literal' && Array.isArray(property.key.value)) {
20
- return property.key.value;
21
- }
22
- return property.key.name || property.key.value || '';
23
- }
24
-
25
- function getPropertyIndex(property, isTopLevel = false) {
26
- const name = getPropertyName(property);
27
-
28
- if (
29
- isTopLevel &&
30
- (property.key.type !== 'Identifier' ||
31
- name.startsWith('&') ||
32
- name.startsWith(':') ||
33
- name.startsWith('@'))
34
- ) {
35
- return null;
36
- }
37
-
38
- let lastGroupIndex = 0;
39
- let maxPropIndex = 0;
40
-
41
- for (let i = 0; i < propertyGroups.length; i++) {
42
- const group = propertyGroups[i];
43
- const propIndex = group.properties.indexOf(name);
44
-
45
- if (propIndex !== -1) {
46
- return i * 1000 + propIndex;
47
- }
48
-
49
- lastGroupIndex = i;
50
- maxPropIndex = Math.max(maxPropIndex, group.properties.length);
51
- }
52
-
53
- if (typeof name === 'string') {
54
- if (name.startsWith('&')) return (propertyGroups.length + 1) * 1000;
55
- if (name.includes(':')) return (propertyGroups.length + 2) * 1000;
56
- if (name.includes('@media')) return (propertyGroups.length + 3) * 1000;
57
- }
58
-
59
- return lastGroupIndex * 1000 + maxPropIndex + 1;
60
- }
61
-
62
- module.exports = {
63
- meta: {
64
- type: 'suggestion',
65
- docs: {
66
- description:
67
- 'Sort CSS properties keeping original order for specific keys',
68
- recommended: true,
69
- },
70
- fixable: 'code',
71
- schema: [],
72
- messages: {
73
- sortProperties:
74
- 'Property "{{property}}" should be at position {{position}}',
75
- },
76
- },
77
-
78
- create(context) {
79
- return {
80
- ObjectExpression(node) {
81
- const sourceCode = getSourceCode(context);
82
- const isTopLevel = !node.parent || node.parent.type !== 'Property';
83
- const properties = node.properties.filter((prop) => prop.key);
84
-
85
- const sorted = [...properties].sort((a, b) => {
86
- const indexA = getPropertyIndex(a, isTopLevel);
87
- const indexB = getPropertyIndex(b, isTopLevel);
88
- return indexA === null || indexB === null ? 0 : indexA - indexB;
89
- });
90
-
91
- const misordered = properties.filter((prop, i) => prop !== sorted[i]);
92
-
93
- if (misordered.length === 0) return;
94
-
95
- const match = sourceCode.getText(node).match(/^{\s*\n(\s*)/);
96
- const indent = match ? match[1] : '';
97
- const lineEnding = match ? '\n' : ' ';
98
-
99
- misordered.forEach((prop) => {
100
- context.report({
101
- node: prop,
102
- messageId: 'sortProperties',
103
- data: {
104
- position: sorted.indexOf(prop) + 1,
105
- property: getPropertyName(prop),
106
- },
107
- fix(fixer) {
108
- const newText = sorted
109
- .map((p) => {
110
- if (Array.isArray(getPropertyName(p))) {
111
- const arrayKey = sourceCode.getText(p.key);
112
- const arrayContent = p.value.properties
113
- .map((inner) => `${indent} ${sourceCode.getText(inner)}`)
114
- .join(`,${lineEnding}`);
115
- return `${indent}${arrayKey}: {\n${arrayContent}\n${indent}}`;
116
- }
117
- return `${indent}${sourceCode.getText(p)}`;
118
- })
119
- .join(`,${lineEnding}`);
120
-
121
- return fixer.replaceTextRange(
122
- [node.range[0] + 1, node.range[1] - 1],
123
- `${lineEnding}${newText}${lineEnding}`,
124
- );
125
- },
126
- });
127
- });
128
- },
129
- };
130
- },
131
- };