@css-modules-kit/eslint-plugin 0.3.0 → 0.4.0
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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -12
- package/dist/index.js.map +1 -1
- package/dist/rules/no-missing-component-file.js +5 -8
- package/dist/rules/no-missing-component-file.js.map +1 -1
- package/dist/rules/no-unused-class-names.js +10 -16
- package/dist/rules/no-unused-class-names.js.map +1 -1
- package/dist/util.js +3 -9
- package/dist/util.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsDa,CAAC;AAG1B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsDa,CAAC;AAG1B,eAAe,MAAM,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
const package_json_1 = __importDefault(require("../package.json"));
|
|
6
|
-
const no_missing_component_file_js_1 = require("./rules/no-missing-component-file.js");
|
|
7
|
-
const no_unused_class_names_js_1 = require("./rules/no-unused-class-names.js");
|
|
1
|
+
import packageJson from '../package.json' with { type: 'json' };
|
|
2
|
+
import { noMissingComponentFile } from './rules/no-missing-component-file.js';
|
|
3
|
+
import { noUnusedClassNames } from './rules/no-unused-class-names.js';
|
|
8
4
|
const plugin = {
|
|
9
5
|
meta: {
|
|
10
|
-
name:
|
|
11
|
-
version:
|
|
6
|
+
name: packageJson.name,
|
|
7
|
+
version: packageJson.version,
|
|
12
8
|
},
|
|
13
9
|
rules: {
|
|
14
|
-
'no-missing-component-file':
|
|
15
|
-
'no-unused-class-names':
|
|
10
|
+
'no-missing-component-file': noMissingComponentFile,
|
|
11
|
+
'no-unused-class-names': noUnusedClassNames,
|
|
16
12
|
},
|
|
17
13
|
configs: {
|
|
18
14
|
recommended: {
|
|
@@ -60,5 +56,5 @@ const plugin = {
|
|
|
60
56
|
},
|
|
61
57
|
};
|
|
62
58
|
plugin.configs.recommended.plugins['css-modules-kit'] = plugin;
|
|
63
|
-
|
|
59
|
+
export default plugin;
|
|
64
60
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,MAAM,MAAM,GAAG;IACb,IAAI,EAAE;QACJ,IAAI,EAAE,WAAW,CAAC,IAAI;QACtB,OAAO,EAAE,WAAW,CAAC,OAAO;KAC7B;IACD,KAAK,EAAE;QACL,2BAA2B,EAAE,sBAAsB;QACnD,uBAAuB,EAAE,kBAAkB;KAC5C;IACD,OAAO,EAAE;QACP,WAAW,EAAE;YACX,eAAe,EAAE;gBACf,YAAY,EAAE;oBACZ,OAAO,EAAE;wBACP,KAAK,EAAE;4BACL,WAAW;4BACX,sBAAsB;4BACtB,qBAAqB;4BACrB,oCAAoC;4BACpC,yCAAyC;4BACzC,4CAA4C;4BAC5C,sDAAsD;4BACtD,EAAE;4BACF,gFAAgF;4BAChF,gCAAgC;4BAChC,gCAAgC;4BAChC,EAAE;4BACF,qHAAqH;4BACrH,OAAO,EACL,uGAAuG;yBAC1G;qBACF;oBACD,UAAU,EAAE;wBACV,WAAW;wBACX,mBAAmB;wBACnB,4CAA4C;wBAC5C,+CAA+C;wBAC/C,8CAA8C;wBAC9C,oDAAoD;wBACpD,EAAE;wBACF,iIAAiI;wBACjI,QAAQ,EAAE,qEAAqE;qBAChF;iBACF;aACF;YACD,OAAO,EAAE;gBACP,iBAAiB,EAAE,EAAE;aACtB;YACD,KAAK,EAAE;gBACL,2CAA2C,EAAE,OAAO;gBACpD,uCAAuC,EAAE,OAAO;aACjD;SACF;KACF;CACsB,CAAC;AAC1B,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,iBAAiB,CAAC,GAAG,MAAM,CAAC;AAE/D,eAAe,MAAM,CAAC"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@css-modules-kit/core");
|
|
5
|
-
const util_js_1 = require("../util.js");
|
|
6
|
-
exports.noMissingComponentFile = {
|
|
1
|
+
import { findComponentFileSync, isCSSModuleFile } from '@css-modules-kit/core';
|
|
2
|
+
import { readFile } from '../util.js';
|
|
3
|
+
export const noMissingComponentFile = {
|
|
7
4
|
meta: {
|
|
8
5
|
type: 'problem',
|
|
9
6
|
language: 'css/css',
|
|
@@ -18,9 +15,9 @@ exports.noMissingComponentFile = {
|
|
|
18
15
|
},
|
|
19
16
|
create(context) {
|
|
20
17
|
const fileName = context.filename;
|
|
21
|
-
if (fileName === undefined || !
|
|
18
|
+
if (fileName === undefined || !isCSSModuleFile(fileName))
|
|
22
19
|
return {};
|
|
23
|
-
const componentFile =
|
|
20
|
+
const componentFile = findComponentFileSync(fileName, readFile);
|
|
24
21
|
if (componentFile === undefined) {
|
|
25
22
|
context.report({
|
|
26
23
|
loc: { line: 1, column: 0 },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-missing-component-file.js","sourceRoot":"","sources":["../../src/rules/no-missing-component-file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"no-missing-component-file.js","sourceRoot":"","sources":["../../src/rules/no-missing-component-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE/E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,CAAC,MAAM,sBAAsB,GAAoB;IACrD,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,SAAS;QACnB,QAAQ,EAAE;YACR,QAAQ,EAAE,gDAAgD;SAC3D;QACD,IAAI,EAAE;YACJ,WAAW,EAAE,6EAA6E;YAC1F,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,oHAAoH;SAC1H;KACF;IACD,MAAM,CAAC,OAAO;QACZ,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAClC,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC;YAAE,OAAO,EAAE,CAAC;QAEpE,MAAM,aAAa,GAAG,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAEhE,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;YAChC,OAAO,CAAC,MAAM,CAAC;gBACb,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;gBAC3B,SAAS,EAAE,UAAU;aACtB,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAC"}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.noUnusedClassNames = void 0;
|
|
7
|
-
const core_1 = require("@css-modules-kit/core");
|
|
8
|
-
const postcss_safe_parser_1 = __importDefault(require("postcss-safe-parser"));
|
|
9
|
-
const util_js_1 = require("../util.js");
|
|
10
|
-
exports.noUnusedClassNames = {
|
|
1
|
+
import { basename, findComponentFileSync, findUsedTokenNames, isCSSModuleFile, parseRule } from '@css-modules-kit/core';
|
|
2
|
+
import safeParser from 'postcss-safe-parser';
|
|
3
|
+
import { readFile } from '../util.js';
|
|
4
|
+
export const noUnusedClassNames = {
|
|
11
5
|
meta: {
|
|
12
6
|
type: 'problem',
|
|
13
7
|
language: 'css/css',
|
|
@@ -22,18 +16,18 @@ exports.noUnusedClassNames = {
|
|
|
22
16
|
},
|
|
23
17
|
create(context) {
|
|
24
18
|
const fileName = context.filename;
|
|
25
|
-
if (fileName === undefined || !
|
|
19
|
+
if (fileName === undefined || !isCSSModuleFile(fileName))
|
|
26
20
|
return {};
|
|
27
|
-
const componentFile =
|
|
21
|
+
const componentFile = findComponentFileSync(fileName, readFile);
|
|
28
22
|
// If the corresponding component file is not found, it is treated as a CSS Module file shared by the entire project.
|
|
29
23
|
// It is difficult to determine where class names in a shared CSS Module file are used. Therefore, it is
|
|
30
24
|
// assumed that all class names are used.
|
|
31
25
|
if (componentFile === undefined)
|
|
32
26
|
return {};
|
|
33
|
-
const usedTokenNames =
|
|
34
|
-
const root = (
|
|
27
|
+
const usedTokenNames = findUsedTokenNames(componentFile.text);
|
|
28
|
+
const root = safeParser(context.sourceCode.text, { from: fileName });
|
|
35
29
|
root.walkRules((rule) => {
|
|
36
|
-
const { classSelectors } =
|
|
30
|
+
const { classSelectors } = parseRule(rule);
|
|
37
31
|
for (const classSelector of classSelectors) {
|
|
38
32
|
if (!usedTokenNames.has(classSelector.name)) {
|
|
39
33
|
context.report({
|
|
@@ -50,7 +44,7 @@ exports.noUnusedClassNames = {
|
|
|
50
44
|
messageId: 'disallow',
|
|
51
45
|
data: {
|
|
52
46
|
className: classSelector.name,
|
|
53
|
-
componentFileName:
|
|
47
|
+
componentFileName: basename(componentFile.fileName),
|
|
54
48
|
},
|
|
55
49
|
});
|
|
56
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-unused-class-names.js","sourceRoot":"","sources":["../../src/rules/no-unused-class-names.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"no-unused-class-names.js","sourceRoot":"","sources":["../../src/rules/no-unused-class-names.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAExH,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,CAAC,MAAM,kBAAkB,GAAoB;IACjD,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,SAAS;QACnB,QAAQ,EAAE;YACR,QAAQ,EAAE,sEAAsE;SACjF;QACD,IAAI,EAAE;YACJ,WAAW,EAAE,iDAAiD;YAC9D,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,gHAAgH;SACtH;KACF;IACD,MAAM,CAAC,OAAO;QACZ,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAClC,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC;YAAE,OAAO,EAAE,CAAC;QAEpE,MAAM,aAAa,GAAG,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAEhE,qHAAqH;QACrH,wGAAwG;QACxG,yCAAyC;QACzC,IAAI,aAAa,KAAK,SAAS;YAAE,OAAO,EAAE,CAAC;QAE3C,MAAM,cAAc,GAAG,kBAAkB,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAE9D,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QACrE,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE;YACtB,MAAM,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;YAE3C,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE,CAAC;gBAC3C,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC5C,OAAO,CAAC,MAAM,CAAC;wBACb,GAAG,EAAE;4BACH,KAAK,EAAE;gCACL,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI;gCAClC,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM;6BACvC;4BACD,GAAG,EAAE;gCACH,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI;gCAChC,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM;6BACrC;yBACF;wBACD,SAAS,EAAE,UAAU;wBACrB,IAAI,EAAE;4BACJ,SAAS,EAAE,aAAa,CAAC,IAAI;4BAC7B,iBAAiB,EAAE,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;yBACpD;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAC"}
|
package/dist/util.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.readFile = readFile;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
function readFile(path) {
|
|
9
|
-
return node_fs_1.default.readFileSync(path, 'utf-8');
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
export function readFile(path) {
|
|
3
|
+
return fs.readFileSync(path, 'utf-8');
|
|
10
4
|
}
|
|
11
5
|
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@css-modules-kit/eslint-plugin",
|
|
3
3
|
"description": "A eslint plugin for CSS Modules",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"type": "
|
|
4
|
+
"version": "0.4.0",
|
|
5
|
+
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"dist"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@css-modules-kit/core": "^0.
|
|
47
|
+
"@css-modules-kit/core": "^0.8.0",
|
|
48
48
|
"postcss-safe-parser": "^7.0.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ESLint } from 'eslint';
|
|
2
|
-
import packageJson from '../package.json';
|
|
2
|
+
import packageJson from '../package.json' with { type: 'json' };
|
|
3
3
|
import { noMissingComponentFile } from './rules/no-missing-component-file.js';
|
|
4
4
|
import { noUnusedClassNames } from './rules/no-unused-class-names.js';
|
|
5
5
|
|
|
@@ -60,4 +60,4 @@ const plugin = {
|
|
|
60
60
|
} satisfies ESLint.Plugin;
|
|
61
61
|
plugin.configs.recommended.plugins['css-modules-kit'] = plugin;
|
|
62
62
|
|
|
63
|
-
export
|
|
63
|
+
export default plugin;
|