@css-modules-kit/stylelint-plugin 0.0.5 → 0.1.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.
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import stylelint from 'stylelint';
|
|
2
|
-
declare function findUsedTokenNames(componentText: string): Set<string>;
|
|
3
2
|
export declare const noUnusedClassNames: stylelint.Plugin;
|
|
4
|
-
export { findUsedTokenNames as findUsedTokenNamesForTest };
|
|
5
3
|
//# sourceMappingURL=no-unused-class-names.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-unused-class-names.d.ts","sourceRoot":"","sources":["../../src/rules/no-unused-class-names.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"no-unused-class-names.d.ts","sourceRoot":"","sources":["../../src/rules/no-unused-class-names.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,WAAW,CAAC;AAsDlC,eAAO,MAAM,kBAAkB,kBAAuC,CAAC"}
|
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.noUnusedClassNames = void 0;
|
|
7
|
-
exports.findUsedTokenNamesForTest = findUsedTokenNames;
|
|
8
7
|
const core_1 = require("@css-modules-kit/core");
|
|
9
8
|
const stylelint_1 = __importDefault(require("stylelint"));
|
|
10
9
|
const util_js_1 = require("../util.js");
|
|
@@ -27,7 +26,7 @@ const ruleFunction = (_primaryOptions, _secondaryOptions, _context) => {
|
|
|
27
26
|
// assumed that all class names are used.
|
|
28
27
|
if (componentFile === undefined)
|
|
29
28
|
return;
|
|
30
|
-
const usedTokenNames = findUsedTokenNames(componentFile.text);
|
|
29
|
+
const usedTokenNames = (0, core_1.findUsedTokenNames)(componentFile.text);
|
|
31
30
|
root.walkRules((rule) => {
|
|
32
31
|
const { classSelectors } = (0, core_1.parseRule)(rule);
|
|
33
32
|
for (const classSelector of classSelectors) {
|
|
@@ -46,22 +45,6 @@ const ruleFunction = (_primaryOptions, _secondaryOptions, _context) => {
|
|
|
46
45
|
});
|
|
47
46
|
};
|
|
48
47
|
};
|
|
49
|
-
/**
|
|
50
|
-
* The syntax pattern for consuming tokens imported from CSS Module.
|
|
51
|
-
* @example `styles.foo`
|
|
52
|
-
*/
|
|
53
|
-
// TODO(#125): Support `styles['foo']` and `styles["foo"]`
|
|
54
|
-
// MEMO: The `xxxStyles.foo` format is not supported, because the css module file for current component file is usually imported with `styles`.
|
|
55
|
-
// It is sufficient to support only the `styles.foo` format.
|
|
56
|
-
const TOKEN_CONSUMER_PATTERN = /styles\.([$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*)/gu;
|
|
57
|
-
function findUsedTokenNames(componentText) {
|
|
58
|
-
const usedClassNames = new Set();
|
|
59
|
-
let match;
|
|
60
|
-
while ((match = TOKEN_CONSUMER_PATTERN.exec(componentText)) !== null) {
|
|
61
|
-
usedClassNames.add(match[1]);
|
|
62
|
-
}
|
|
63
|
-
return usedClassNames;
|
|
64
|
-
}
|
|
65
48
|
ruleFunction.ruleName = ruleName;
|
|
66
49
|
ruleFunction.messages = messages;
|
|
67
50
|
ruleFunction.meta = meta;
|
|
@@ -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,gDAAoH;AAEpH,0DAAkC;AAClC,wCAAsC;AAEtC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,mBAAS,CAAC;AAE1C,MAAM,QAAQ,GAAG,uCAAuC,CAAC;AAEzD,MAAM,QAAQ,GAAG,KAAK,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Aa,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM;wBACrC,QAAQ,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM;wBACtC,IAAI,EAAE,aAAa,CAAC,IAAI;qBACzB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,YAAY,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACjC,YAAY,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACjC,YAAY,CAAC,IAAI,GAAG,IAAI,CAAC;AAEZ,QAAA,kBAAkB,GAAG,YAAY,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@css-modules-kit/stylelint-plugin",
|
|
3
3
|
"description": "A stylelint plugin for CSS Modules",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"repository": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@css-modules-kit/core": "^0.0
|
|
40
|
+
"@css-modules-kit/core": "^0.1.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"stylelint": "^16.0.0"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { basename, findComponentFile, isCSSModuleFile, parseRule } from '@css-modules-kit/core';
|
|
1
|
+
import { basename, findComponentFile, findUsedTokenNames, isCSSModuleFile, parseRule } from '@css-modules-kit/core';
|
|
2
2
|
import type { Rule } from 'stylelint';
|
|
3
3
|
import stylelint from 'stylelint';
|
|
4
4
|
import { readFile } from '../util.js';
|
|
@@ -50,27 +50,8 @@ const ruleFunction: Rule = (_primaryOptions, _secondaryOptions, _context) => {
|
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
/**
|
|
54
|
-
* The syntax pattern for consuming tokens imported from CSS Module.
|
|
55
|
-
* @example `styles.foo`
|
|
56
|
-
*/
|
|
57
|
-
// TODO(#125): Support `styles['foo']` and `styles["foo"]`
|
|
58
|
-
// MEMO: The `xxxStyles.foo` format is not supported, because the css module file for current component file is usually imported with `styles`.
|
|
59
|
-
// It is sufficient to support only the `styles.foo` format.
|
|
60
|
-
const TOKEN_CONSUMER_PATTERN = /styles\.([$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*)/gu;
|
|
61
|
-
|
|
62
|
-
function findUsedTokenNames(componentText: string): Set<string> {
|
|
63
|
-
const usedClassNames = new Set<string>();
|
|
64
|
-
let match;
|
|
65
|
-
while ((match = TOKEN_CONSUMER_PATTERN.exec(componentText)) !== null) {
|
|
66
|
-
usedClassNames.add(match[1]!);
|
|
67
|
-
}
|
|
68
|
-
return usedClassNames;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
53
|
ruleFunction.ruleName = ruleName;
|
|
72
54
|
ruleFunction.messages = messages;
|
|
73
55
|
ruleFunction.meta = meta;
|
|
74
56
|
|
|
75
57
|
export const noUnusedClassNames = createPlugin(ruleName, ruleFunction);
|
|
76
|
-
export { findUsedTokenNames as findUsedTokenNamesForTest };
|