stylelint-find-new-rules 6.0.0 → 6.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.
- package/eslint.config.mjs +15 -1
- package/index.d.ts +49 -0
- package/lib/utils/rules.js +2 -1
- package/package.json +13 -6
- package/test/fixtures/duplicate-plugin.config.mjs +20 -0
- package/test/rules.test.js +16 -0
package/eslint.config.mjs
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import config from '@pulsanova/eslint-config-node';
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
...config,
|
|
5
|
+
{
|
|
6
|
+
files: ['index.d.ts'],
|
|
7
|
+
languageOptions: {
|
|
8
|
+
parserOptions: {
|
|
9
|
+
projectService: {
|
|
10
|
+
allowDefaultProject: ['index.d.ts'],
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
];
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stylelint rule metadata returned by stylelint-find-new-rules.
|
|
3
|
+
*/
|
|
4
|
+
export type Rule = {
|
|
5
|
+
/** Rule name, including the plugin namespace when present. */
|
|
6
|
+
name: string,
|
|
7
|
+
|
|
8
|
+
/** Documentation URL when it can be resolved. */
|
|
9
|
+
url: string | null,
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Whether the rule is marked as deprecated.
|
|
13
|
+
*
|
|
14
|
+
* Absent when the configured rule cannot be matched to an available rule.
|
|
15
|
+
*/
|
|
16
|
+
isDeprecated?: boolean,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Result of comparing a resolved Stylelint config with all available rules.
|
|
21
|
+
*/
|
|
22
|
+
export type Result = {
|
|
23
|
+
/** All available core and plugin rules. */
|
|
24
|
+
all: Rule[],
|
|
25
|
+
|
|
26
|
+
/** Rules configured in the resolved Stylelint config. */
|
|
27
|
+
used: Rule[],
|
|
28
|
+
|
|
29
|
+
/** Available non-deprecated rules missing from the config. */
|
|
30
|
+
unused: Rule[],
|
|
31
|
+
|
|
32
|
+
/** Configured rules that are not available. */
|
|
33
|
+
invalid: Rule[],
|
|
34
|
+
|
|
35
|
+
/** Configured rules marked as deprecated. */
|
|
36
|
+
deprecated: Rule[],
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Finds available, configured, unused, invalid, and deprecated Stylelint rules.
|
|
41
|
+
*
|
|
42
|
+
* @param configFile - Path to a Stylelint config file.
|
|
43
|
+
*
|
|
44
|
+
* @returns A promise resolved with the available, configured, unused,
|
|
45
|
+
* invalid, and deprecated rules (see {@link Result}).
|
|
46
|
+
*/
|
|
47
|
+
declare const stylelintFindNewRules: (configFile?: string | null) => Promise<Result>;
|
|
48
|
+
|
|
49
|
+
export default stylelintFindNewRules;
|
package/lib/utils/rules.js
CHANGED
|
@@ -35,7 +35,8 @@ export const getAllRules = async (config) => {
|
|
|
35
35
|
allRules.push(...pluginsRules.flat());
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
const rulesByName = new Map(allRules.map((rule) => [rule.name, rule]));
|
|
39
|
+
return [...rulesByName.values()];
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
export const getUsedRules = async (config, allRules = null) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stylelint-find-new-rules",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Find stylelint rules that you don't have in your config",
|
|
5
5
|
"homepage": "https://github.com/Donov4n/stylelint-find-new-rules",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,23 +12,30 @@
|
|
|
12
12
|
"contributors": [
|
|
13
13
|
"Alex Ilyaev"
|
|
14
14
|
],
|
|
15
|
-
"exports":
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./index.d.ts",
|
|
18
|
+
"default": "./lib/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"types": "./index.d.ts",
|
|
16
22
|
"type": "module",
|
|
17
23
|
"bin": {
|
|
18
24
|
"stylelint-find-new-rules": "bin/stylelint-find-new-rules.js"
|
|
19
25
|
},
|
|
20
26
|
"scripts": {
|
|
21
|
-
"lint": "eslint --ext .js lib"
|
|
27
|
+
"lint": "eslint --ext .js lib",
|
|
28
|
+
"test": "node --test test/*.test.js"
|
|
22
29
|
},
|
|
23
30
|
"dependencies": {
|
|
24
31
|
"columnify": "~1.6.0",
|
|
25
32
|
"picocolors": "^1.1.1",
|
|
26
|
-
"read-pkg": "^10.
|
|
33
|
+
"read-pkg": "^10.1.0",
|
|
27
34
|
"yargs": "~18.0.0"
|
|
28
35
|
},
|
|
29
36
|
"devDependencies": {
|
|
30
|
-
"@pulsanova/eslint-config-node": "~3.
|
|
31
|
-
"eslint": "~
|
|
37
|
+
"@pulsanova/eslint-config-node": "~3.3.3",
|
|
38
|
+
"eslint": "~10.6.0",
|
|
32
39
|
"stylelint": "^17"
|
|
33
40
|
},
|
|
34
41
|
"peerDependencies": {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const plugin = [
|
|
2
|
+
{
|
|
3
|
+
ruleName: 'fixture/no-css',
|
|
4
|
+
rule: () => {},
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
ruleName: 'fixture/no-scss',
|
|
8
|
+
rule: () => {},
|
|
9
|
+
},
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
// The same plugin is listed twice to emulate separate CSS and SCSS configs.
|
|
14
|
+
plugins: [plugin, plugin],
|
|
15
|
+
rules: {
|
|
16
|
+
'fixture/no-css': true,
|
|
17
|
+
// `fixture/no-scss` is intentionally absent from `rules`,
|
|
18
|
+
// so it should be reported as unused once.
|
|
19
|
+
},
|
|
20
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import test from 'node:test';
|
|
4
|
+
import stylelintFindNewRules from '../lib/index.js';
|
|
5
|
+
|
|
6
|
+
const countRules = (rules, name) => rules.filter((rule) => rule.name === name).length;
|
|
7
|
+
|
|
8
|
+
test('Deduplicates plugin rules when the same plugin is configured more than once', async () => {
|
|
9
|
+
const configFile = fileURLToPath(new URL('./fixtures/duplicate-plugin.config.mjs', import.meta.url));
|
|
10
|
+
const { all, unused } = await stylelintFindNewRules(configFile);
|
|
11
|
+
|
|
12
|
+
assert.equal(countRules(all, 'fixture/no-css'), 1);
|
|
13
|
+
assert.equal(countRules(all, 'fixture/no-scss'), 1);
|
|
14
|
+
assert.equal(countRules(unused, 'fixture/no-css'), 0);
|
|
15
|
+
assert.equal(countRules(unused, 'fixture/no-scss'), 1);
|
|
16
|
+
});
|