@css-modules-kit/stylelint-plugin 0.0.5 → 0.2.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/README.md CHANGED
@@ -14,15 +14,10 @@ npm i -D @css-modules-kit/stylelint-plugin
14
14
  // stylelint.config.js
15
15
  /** @type {import('stylelint').Config} */
16
16
  export default {
17
- plugins: ['@css-modules-kit/stylelint-plugin'],
18
- rules: {
19
- 'css-modules-kit/no-unused-class-names': true,
20
- 'css-modules-kit/no-missing-component-file': true,
21
- },
17
+ extends: ['@css-modules-kit/stylelint-plugin/recommended'],
22
18
  };
23
19
  ```
24
20
 
25
21
  ## Rules
26
22
 
27
- - `css-modules-kit/no-unused-class-names`
28
- - `css-modules-kit/no-missing-component-file`
23
+ The same rules as eslint-plugin are provided. See [the eslint-plugin documentation](https://github.com/mizdra/css-modules-kit/blob/main/packages/eslint-plugin/README.md#rules) for a list of rules.
@@ -0,0 +1,4 @@
1
+ import type { Config } from 'stylelint';
2
+ declare const recommendedConfig: Config;
3
+ export = recommendedConfig;
4
+ //# sourceMappingURL=recommended.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recommended.d.ts","sourceRoot":"","sources":["../src/recommended.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC,QAAA,MAAM,iBAAiB,EAAE,MAwCxB,CAAC;AAEF,SAAS,iBAAiB,CAAC"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ const recommendedConfig = {
3
+ plugins: ['@css-modules-kit/stylelint-plugin'],
4
+ languageOptions: {
5
+ syntax: {
6
+ atRules: {
7
+ value: {
8
+ // Example:
9
+ // - `@value a: #123;`
10
+ // - `@value empty:;`
11
+ // - `@value withoutSemicolon #123;`
12
+ // - `@value a from './test.module.css';`
13
+ // - `@value a, b from './test.module.css';`
14
+ // - `@value a as aliased_a from './test.module.css';`
15
+ //
16
+ // CSS Modules Kit does not support the following for implementation simplicity:
17
+ // - `@value (a, b) from '...';`
18
+ // - `@value a from moduleName;`
19
+ //
20
+ // ref: https://github.com/css-modules/postcss-icss-values/blob/acdf34a62cc2537a9507b1e9fd34db486e5cb0f8/test/test.js
21
+ prelude: '<custom-ident> :? <declaration-value>? | [ [ <custom-ident> [ as <custom-ident> ]? ]# from <string> ]',
22
+ },
23
+ },
24
+ properties: {
25
+ // Example:
26
+ // - `composes: a;`
27
+ // - `composes: a from './test.module.css';`
28
+ // - `composes: a, b from './test.module.css';`
29
+ // - `composes: a b from './test.module.css';`
30
+ // - `composes: global(a) from './test.module.css';`
31
+ //
32
+ // ref: https://github.com/css-modules/postcss-modules-extract-imports/blob/16f9c570e517cf3558b88cf96dcadf794230965a/src/index.js
33
+ composes: '[ [ <custom-ident> | global(<custom-ident>) ] ,? ]+ [ from <string> ]?',
34
+ },
35
+ },
36
+ },
37
+ rules: {
38
+ 'css-modules-kit/no-unused-class-names': true,
39
+ 'css-modules-kit/no-missing-component-file': true,
40
+ },
41
+ };
42
+ module.exports = recommendedConfig;
43
+ //# sourceMappingURL=recommended.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recommended.js","sourceRoot":"","sources":["../src/recommended.ts"],"names":[],"mappings":";AAEA,MAAM,iBAAiB,GAAW;IAChC,OAAO,EAAE,CAAC,mCAAmC,CAAC;IAC9C,eAAe,EAAE;QACf,MAAM,EAAE;YACN,OAAO,EAAE;gBACP,KAAK,EAAE;oBACL,WAAW;oBACX,sBAAsB;oBACtB,qBAAqB;oBACrB,oCAAoC;oBACpC,yCAAyC;oBACzC,4CAA4C;oBAC5C,sDAAsD;oBACtD,EAAE;oBACF,gFAAgF;oBAChF,gCAAgC;oBAChC,gCAAgC;oBAChC,EAAE;oBACF,qHAAqH;oBACrH,OAAO,EACL,uGAAuG;iBAC1G;aACF;YACD,UAAU,EAAE;gBACV,WAAW;gBACX,mBAAmB;gBACnB,4CAA4C;gBAC5C,+CAA+C;gBAC/C,8CAA8C;gBAC9C,oDAAoD;gBACpD,EAAE;gBACF,iIAAiI;gBACjI,QAAQ,EAAE,wEAAwE;aACnF;SACF;KACF;IACD,KAAK,EAAE;QACL,uCAAuC,EAAE,IAAI;QAC7C,2CAA2C,EAAE,IAAI;KAClD;CACF,CAAC;AAEF,iBAAS,iBAAiB,CAAC"}
@@ -13,7 +13,7 @@ const messages = utils.ruleMessages(ruleName, {
13
13
  disallow: () => `The corresponding component file is not found.`,
14
14
  });
15
15
  const meta = {
16
- url: 'https://github.com/mizdra/css-modules-kit/blob/main/packages/stylelint-plugin/docs/rules/no-missing-component-file.md',
16
+ url: 'https://github.com/mizdra/css-modules-kit/blob/main/packages/eslint-plugin/docs/rules/no-missing-component-file.md',
17
17
  };
18
18
  const ruleFunction = (_primaryOptions, _secondaryOptions, _context) => {
19
19
  return async (root, result) => {
@@ -1 +1 @@
1
- {"version":3,"file":"no-missing-component-file.js","sourceRoot":"","sources":["../../src/rules/no-missing-component-file.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA2E;AAE3E,0DAAkC;AAClC,wCAAsC;AAEtC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,mBAAS,CAAC;AAE1C,MAAM,QAAQ,GAAG,2CAA2C,CAAC;AAE7D,MAAM,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE;IAC5C,QAAQ,EAAE,GAAG,EAAE,CAAC,gDAAgD;CACjE,CAAC,CAAC;AAEH,MAAM,IAAI,GAAG;IACX,GAAG,EAAE,uHAAuH;CAC7H,CAAC;AAEF,MAAM,YAAY,GAAS,CAAC,eAAe,EAAE,iBAAiB,EAAE,QAAQ,EAAE,EAAE;IAC1E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC;QACzC,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,IAAA,sBAAe,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CAAC;QACzC,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,IAAA,sBAAe,EAAC,QAAQ,CAAC;YAAE,OAAO;QAEjE,MAAM,aAAa,GAAG,MAAM,IAAA,wBAAiB,EAAC,QAAQ,EAAE,kBAAQ,CAAC,CAAC;QAElE,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;YAChC,KAAK,CAAC,MAAM,CAAC;gBACX,MAAM;gBACN,QAAQ;gBACR,OAAO,EAAE,QAAQ,CAAC,QAAQ,EAAE;gBAC5B,IAAI,EAAE,IAAI;gBACV,KAAK,EAAE,CAAC;gBACR,QAAQ,EAAE,CAAC;aACZ,CAAC,CAAC;QACL,CAAC;IACH,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,sBAAsB,GAAG,YAAY,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC"}
@@ -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;AA2DlC,iBAAS,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAO9D;AAMD,eAAO,MAAM,kBAAkB,kBAAuC,CAAC;AACvE,OAAO,EAAE,kBAAkB,IAAI,yBAAyB,EAAE,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");
@@ -14,7 +13,7 @@ const messages = utils.ruleMessages(ruleName, {
14
13
  disallow: (className, componentFileName) => `"${className}" is defined but never used in "${(0, core_1.basename)(componentFileName)}"`,
15
14
  });
16
15
  const meta = {
17
- url: 'https://github.com/mizdra/css-modules-kit/blob/main/packages/stylelint-plugin/docs/rules/no-unused-class-names.md',
16
+ url: 'https://github.com/mizdra/css-modules-kit/blob/main/packages/eslint-plugin/docs/rules/no-unused-class-names.md',
18
17
  };
19
18
  const ruleFunction = (_primaryOptions, _secondaryOptions, _context) => {
20
19
  return async (root, result) => {
@@ -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":";;;;;;AA2E+B,uDAAyB;AA3ExD,gDAAgG;AAEhG,0DAAkC;AAClC,wCAAsC;AAEtC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,mBAAS,CAAC;AAE1C,MAAM,QAAQ,GAAG,uCAAuC,CAAC;AAEzD,MAAM,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE;IAC5C,QAAQ,EAAE,CAAC,SAAiB,EAAE,iBAAyB,EAAE,EAAE,CACzD,IAAI,SAAS,mCAAmC,IAAA,eAAQ,EAAC,iBAAiB,CAAC,GAAG;CACjF,CAAC,CAAC;AAEH,MAAM,IAAI,GAAG;IACX,GAAG,EAAE,mHAAmH;CACzH,CAAC;AAEF,MAAM,YAAY,GAAS,CAAC,eAAe,EAAE,iBAAiB,EAAE,QAAQ,EAAE,EAAE;IAC1E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC;QACzC,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,IAAA,sBAAe,EAAC,QAAQ,CAAC;YAAE,OAAO;QAEjE,MAAM,aAAa,GAAG,MAAM,IAAA,wBAAiB,EAAC,QAAQ,EAAE,kBAAQ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AAM,cAAc,GAAG,IAAA,yBAAkB,EAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAE9D,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE;YACtB,MAAM,EAAE,cAAc,EAAE,GAAG,IAAA,gBAAS,EAAC,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,KAAK,CAAC,MAAM,CAAC;wBACX,MAAM;wBACN,QAAQ;wBACR,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAC;wBACtE,IAAI,EAAE,IAAI;wBACV,KAAK,EAAE,aAAa,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.5",
4
+ "version": "0.2.0",
5
5
  "type": "commonjs",
6
6
  "sideEffects": false,
7
7
  "repository": {
@@ -12,7 +12,20 @@
12
12
  "author": "mizdra <pp.mizdra@gmail.com>",
13
13
  "license": "MIT",
14
14
  "private": false,
15
- "main": "./dist/index.js",
15
+ "exports": {
16
+ ".": {
17
+ "import": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ }
21
+ },
22
+ "./recommended": {
23
+ "import": {
24
+ "types": "./dist/recommended.d.ts",
25
+ "default": "./dist/recommended.js"
26
+ }
27
+ }
28
+ },
16
29
  "scripts": {
17
30
  "build": "tsc -b tsconfig.build.json"
18
31
  },
@@ -37,7 +50,7 @@
37
50
  "dist"
38
51
  ],
39
52
  "dependencies": {
40
- "@css-modules-kit/core": "^0.0.5"
53
+ "@css-modules-kit/core": "^0.2.0"
41
54
  },
42
55
  "peerDependencies": {
43
56
  "stylelint": "^16.0.0"
@@ -0,0 +1,45 @@
1
+ import type { Config } from 'stylelint';
2
+
3
+ const recommendedConfig: Config = {
4
+ plugins: ['@css-modules-kit/stylelint-plugin'],
5
+ languageOptions: {
6
+ syntax: {
7
+ atRules: {
8
+ value: {
9
+ // Example:
10
+ // - `@value a: #123;`
11
+ // - `@value empty:;`
12
+ // - `@value withoutSemicolon #123;`
13
+ // - `@value a from './test.module.css';`
14
+ // - `@value a, b from './test.module.css';`
15
+ // - `@value a as aliased_a from './test.module.css';`
16
+ //
17
+ // CSS Modules Kit does not support the following for implementation simplicity:
18
+ // - `@value (a, b) from '...';`
19
+ // - `@value a from moduleName;`
20
+ //
21
+ // ref: https://github.com/css-modules/postcss-icss-values/blob/acdf34a62cc2537a9507b1e9fd34db486e5cb0f8/test/test.js
22
+ prelude:
23
+ '<custom-ident> :? <declaration-value>? | [ [ <custom-ident> [ as <custom-ident> ]? ]# from <string> ]',
24
+ },
25
+ },
26
+ properties: {
27
+ // Example:
28
+ // - `composes: a;`
29
+ // - `composes: a from './test.module.css';`
30
+ // - `composes: a, b from './test.module.css';`
31
+ // - `composes: a b from './test.module.css';`
32
+ // - `composes: global(a) from './test.module.css';`
33
+ //
34
+ // ref: https://github.com/css-modules/postcss-modules-extract-imports/blob/16f9c570e517cf3558b88cf96dcadf794230965a/src/index.js
35
+ composes: '[ [ <custom-ident> | global(<custom-ident>) ] ,? ]+ [ from <string> ]?',
36
+ },
37
+ },
38
+ },
39
+ rules: {
40
+ 'css-modules-kit/no-unused-class-names': true,
41
+ 'css-modules-kit/no-missing-component-file': true,
42
+ },
43
+ };
44
+
45
+ export = recommendedConfig;
@@ -1,5 +1,5 @@
1
1
  import { findComponentFile, isCSSModuleFile } from '@css-modules-kit/core';
2
- import type { Rule } from 'stylelint';
2
+ import type { Rule, RuleMeta } from 'stylelint';
3
3
  import stylelint from 'stylelint';
4
4
  import { readFile } from '../util.js';
5
5
 
@@ -11,8 +11,8 @@ const messages = utils.ruleMessages(ruleName, {
11
11
  disallow: () => `The corresponding component file is not found.`,
12
12
  });
13
13
 
14
- const meta = {
15
- url: 'https://github.com/mizdra/css-modules-kit/blob/main/packages/stylelint-plugin/docs/rules/no-missing-component-file.md',
14
+ const meta: RuleMeta = {
15
+ url: 'https://github.com/mizdra/css-modules-kit/blob/main/packages/eslint-plugin/docs/rules/no-missing-component-file.md',
16
16
  };
17
17
 
18
18
  const ruleFunction: Rule = (_primaryOptions, _secondaryOptions, _context) => {
@@ -1,5 +1,5 @@
1
- import { basename, findComponentFile, isCSSModuleFile, parseRule } from '@css-modules-kit/core';
2
- import type { Rule } from 'stylelint';
1
+ import { basename, findComponentFile, findUsedTokenNames, isCSSModuleFile, parseRule } from '@css-modules-kit/core';
2
+ import type { Rule, RuleMeta } from 'stylelint';
3
3
  import stylelint from 'stylelint';
4
4
  import { readFile } from '../util.js';
5
5
 
@@ -12,8 +12,8 @@ const messages = utils.ruleMessages(ruleName, {
12
12
  `"${className}" is defined but never used in "${basename(componentFileName)}"`,
13
13
  });
14
14
 
15
- const meta = {
16
- url: 'https://github.com/mizdra/css-modules-kit/blob/main/packages/stylelint-plugin/docs/rules/no-unused-class-names.md',
15
+ const meta: RuleMeta = {
16
+ url: 'https://github.com/mizdra/css-modules-kit/blob/main/packages/eslint-plugin/docs/rules/no-unused-class-names.md',
17
17
  };
18
18
 
19
19
  const ruleFunction: Rule = (_primaryOptions, _secondaryOptions, _context) => {
@@ -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 };