stylelint-find-new-rules 4.1.2 → 5.0.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 +19 -19
- package/bin/stylelint-find-new-rules.js +1 -3
- package/lib/cli.js +14 -9
- package/lib/index.js +9 -10
- package/lib/utils/extractRuleMeta.js +1 -3
- package/lib/utils/print.js +6 -9
- package/lib/utils/rules.js +36 -31
- package/package.json +12 -9
package/README.md
CHANGED
|
@@ -72,23 +72,23 @@ npm run --silent stylelint-find-rules
|
|
|
72
72
|
## API Usage
|
|
73
73
|
|
|
74
74
|
```js
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
stylelintRules('./my-config-file.js')
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
75
|
+
import stylelintRules from 'stylelint-find-new-rules';
|
|
76
|
+
|
|
77
|
+
const rules = await stylelintRules('./my-config-file.js');
|
|
78
|
+
|
|
79
|
+
// `rules` format:
|
|
80
|
+
// {
|
|
81
|
+
// used : [[RULE], [RULE], ...],
|
|
82
|
+
// all : [[RULE], [RULE], ...],
|
|
83
|
+
// unused : [[RULE], [RULE], ...],
|
|
84
|
+
// deprecated : [[RULE], [RULE], ...],
|
|
85
|
+
// invalid : [[RULE], [RULE], ...]
|
|
86
|
+
// }
|
|
87
|
+
//
|
|
88
|
+
// `[RULE]` format:
|
|
89
|
+
// {
|
|
90
|
+
// name : '[Rule name]',
|
|
91
|
+
// url : '[URL of the rule's documentation if available or `null`]',
|
|
92
|
+
// isDeprecated : [boolean]
|
|
93
|
+
// }
|
|
94
94
|
```
|
package/lib/cli.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import yargs from 'yargs';
|
|
2
|
+
import { hideBin } from 'yargs/helpers';
|
|
3
|
+
import colors from 'picocolors';
|
|
4
|
+
import { readPackageSync } from 'read-pkg';
|
|
5
|
+
import process from 'node:process';
|
|
6
|
+
import { dirname } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import standalone from './index.js';
|
|
9
|
+
import { print, printRules } from './utils/print.js';
|
|
9
10
|
|
|
10
11
|
const DEFAULT_OPTIONS = {
|
|
11
12
|
unused: true,
|
|
@@ -27,7 +28,7 @@ const handleError = (err) => {
|
|
|
27
28
|
|
|
28
29
|
process.on('unhandledRejection', handleError);
|
|
29
30
|
|
|
30
|
-
const { argv } = yargs
|
|
31
|
+
const { argv } = yargs(hideBin(process.argv))
|
|
31
32
|
.usage('stylelint-find-new-rules [options] <file>')
|
|
32
33
|
.example('stylelint-find-new-rules')
|
|
33
34
|
.example('stylelint-find-new-rules --no-d --no-i')
|
|
@@ -91,6 +92,10 @@ if (!options.unused && !options.deprecated && !options.current && !options.avail
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
const printResults = (rules) => {
|
|
95
|
+
const pkg = readPackageSync({
|
|
96
|
+
cwd: dirname(dirname(fileURLToPath(import.meta.url))),
|
|
97
|
+
normalize: false,
|
|
98
|
+
});
|
|
94
99
|
print(`stylelint-find-new-rules v${pkg.version}`);
|
|
95
100
|
|
|
96
101
|
if (options.current) {
|
package/lib/index.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import stylelint from 'stylelint';
|
|
3
|
+
import { getAllRules, getUsedRules } from './utils/rules.js';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
+
export default async (configFile = null) => {
|
|
6
|
+
const config = await stylelint.resolveConfig(process.cwd(), { configFile });
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const all = getAllRules(config);
|
|
10
|
-
const used = getUsedRules(config, all);
|
|
8
|
+
const all = await getAllRules(config);
|
|
9
|
+
const used = await getUsedRules(config, all);
|
|
11
10
|
const deprecated = used.filter(({ isDeprecated }) => isDeprecated);
|
|
12
11
|
|
|
13
12
|
const unused = all.filter(
|
|
14
13
|
({ name, isDeprecated }) => (
|
|
15
|
-
!isDeprecated && !used.
|
|
14
|
+
!isDeprecated && !used.some((_rule) => _rule.name === name)
|
|
16
15
|
),
|
|
17
16
|
);
|
|
18
17
|
|
|
19
18
|
const invalid = used.filter(
|
|
20
|
-
({ name }) => !all.
|
|
19
|
+
({ name }) => !all.some((_rule) => _rule.name === name),
|
|
21
20
|
);
|
|
22
21
|
|
|
23
22
|
return { all, used, unused, invalid, deprecated };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const PLUGINS_URL_RESOLVER = {
|
|
4
2
|
'stylelint': (rule) => (
|
|
5
3
|
`https://stylelint.io/user-guide/rules/list/${rule}`
|
|
@@ -54,4 +52,4 @@ const extractRuleMeta = (name, rule, isPlugin) => {
|
|
|
54
52
|
return { name, isDeprecated: deprecated, url };
|
|
55
53
|
};
|
|
56
54
|
|
|
57
|
-
|
|
55
|
+
export default extractRuleMeta;
|
package/lib/utils/print.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import columnify from 'columnify';
|
|
2
|
+
import colors from 'picocolors';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
import os from 'node:os';
|
|
2
5
|
|
|
3
|
-
const
|
|
4
|
-
const colors = require('picocolors');
|
|
5
|
-
const os = require('os');
|
|
6
|
-
|
|
7
|
-
const print = (output) => {
|
|
6
|
+
export const print = (output) => {
|
|
8
7
|
process.stdout.write(output);
|
|
9
8
|
process.stdout.write(os.EOL + os.EOL);
|
|
10
9
|
};
|
|
11
10
|
|
|
12
|
-
const printRules = (heading, rules, options = {}) => {
|
|
11
|
+
export const printRules = (heading, rules, options = {}) => {
|
|
13
12
|
const defaults = { color: null, showLink: true };
|
|
14
13
|
const { color, showLink } = { ...defaults, ...options };
|
|
15
14
|
|
|
@@ -34,5 +33,3 @@ const printRules = (heading, rules, options = {}) => {
|
|
|
34
33
|
print(colors.underline(colors[color || 'blue'](heading)));
|
|
35
34
|
print(columnify(rulesToPrint, {}));
|
|
36
35
|
};
|
|
37
|
-
|
|
38
|
-
module.exports = { print, printRules };
|
package/lib/utils/rules.js
CHANGED
|
@@ -1,39 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
import { isAbsolute } from 'node:path';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import stylelint from 'stylelint';
|
|
4
|
+
import extractRuleMeta from './extractRuleMeta.js';
|
|
2
5
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const rules = Object.entries(coreRules).map(([name, rule]) => (
|
|
8
|
-
extractRuleMeta(name, rule, false)
|
|
9
|
-
));
|
|
6
|
+
export const getAllRules = async (config) => {
|
|
7
|
+
const allRules = Object.entries(stylelint.rules).map(
|
|
8
|
+
([name, rule]) => extractRuleMeta(name, rule, false),
|
|
9
|
+
);
|
|
10
10
|
|
|
11
11
|
if (config.plugins) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
12
|
+
// @see https://github.com/stylelint/stylelint/blob/16.1.0/lib/augmentConfig.mjs#L317
|
|
13
|
+
const plugins = [config.plugins].flat();
|
|
14
|
+
const pluginsRules = await Promise.all(plugins.map(async (plugin) => {
|
|
15
|
+
let rawPluginRules = typeof plugin !== 'string' ? plugin : (
|
|
16
|
+
await import(
|
|
17
|
+
isAbsolute(plugin)
|
|
18
|
+
? pathToFileURL(plugin).toString()
|
|
19
|
+
: plugin
|
|
20
|
+
)
|
|
21
|
+
);
|
|
22
|
+
rawPluginRules = rawPluginRules.default || rawPluginRules; // - ESM / CommonJS.
|
|
23
|
+
rawPluginRules = [rawPluginRules].flat();
|
|
24
|
+
|
|
25
|
+
return rawPluginRules.reduce(
|
|
26
|
+
(pluginRules, { ruleName: name, rule }) => {
|
|
27
|
+
if (name?.includes('/')) {
|
|
28
|
+
pluginRules.push(extractRuleMeta(name, rule, true));
|
|
29
|
+
}
|
|
30
|
+
return pluginRules;
|
|
31
|
+
},
|
|
32
|
+
[],
|
|
33
|
+
);
|
|
34
|
+
}));
|
|
35
|
+
allRules.push(...pluginsRules.flat());
|
|
28
36
|
}
|
|
29
37
|
|
|
30
|
-
return
|
|
38
|
+
return allRules;
|
|
31
39
|
};
|
|
32
40
|
|
|
33
|
-
const getUsedRules = (config, allRules = null) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
41
|
+
export const getUsedRules = async (config, allRules = null) => {
|
|
42
|
+
// eslint-disable-next-line require-atomic-updates
|
|
43
|
+
allRules ??= await getAllRules(config);
|
|
37
44
|
|
|
38
45
|
const rules = Object.keys(config.rules || {})
|
|
39
46
|
.filter((value, index, self) => self.indexOf(value) === index)
|
|
@@ -44,5 +51,3 @@ const getUsedRules = (config, allRules = null) => {
|
|
|
44
51
|
|
|
45
52
|
return rules;
|
|
46
53
|
};
|
|
47
|
-
|
|
48
|
-
module.exports = { getUsedRules, getAllRules };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stylelint-find-new-rules",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.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",
|
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
"contributors": [
|
|
10
10
|
"Alex Ilyaev"
|
|
11
11
|
],
|
|
12
|
-
"
|
|
12
|
+
"exports": "./lib/index.js",
|
|
13
|
+
"type": "module",
|
|
13
14
|
"bin": {
|
|
14
|
-
"stylelint-find-new-rules": "bin/stylelint-find-new-rules.js"
|
|
15
|
+
"stylelint-find-new-rules": "./bin/stylelint-find-new-rules.js"
|
|
15
16
|
},
|
|
16
17
|
"scripts": {
|
|
17
18
|
"lint": "eslint --ext .js lib"
|
|
@@ -19,17 +20,19 @@
|
|
|
19
20
|
"dependencies": {
|
|
20
21
|
"columnify": "~1.6.0",
|
|
21
22
|
"picocolors": "^1.0.0",
|
|
22
|
-
"
|
|
23
|
+
"read-package-up": "^11.0.0",
|
|
24
|
+
"read-pkg": "^9.0.1",
|
|
25
|
+
"yargs": "~17.7.2"
|
|
23
26
|
},
|
|
24
27
|
"devDependencies": {
|
|
25
|
-
"@pulsanova/eslint-config-
|
|
26
|
-
"eslint": "^8.
|
|
27
|
-
"stylelint": "^
|
|
28
|
+
"@pulsanova/eslint-config-node": "~2.3.0",
|
|
29
|
+
"eslint": "^8.56.0",
|
|
30
|
+
"stylelint": "^16"
|
|
28
31
|
},
|
|
29
32
|
"peerDependencies": {
|
|
30
|
-
"stylelint": "^
|
|
33
|
+
"stylelint": "^16"
|
|
31
34
|
},
|
|
32
35
|
"engines": {
|
|
33
|
-
"node": ">=
|
|
36
|
+
"node": ">=18.12.0"
|
|
34
37
|
}
|
|
35
38
|
}
|