@jhae/stylelint-config-verifier 1.2.0 → 1.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/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-

|
|
2
|
-

|
|
2
|
+

|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
5
6
|
|
|
6
7
|
# Stylelint Config Verifier
|
|
7
8
|
|
|
@@ -96,20 +97,19 @@ Example Stylelint configuration file:
|
|
|
96
97
|
|
|
97
98
|
```yaml
|
|
98
99
|
rules:
|
|
99
|
-
at-rule-disallowed-list:
|
|
100
|
-
- import
|
|
100
|
+
at-rule-disallowed-list: null
|
|
101
101
|
|
|
102
102
|
overrides:
|
|
103
103
|
- files:
|
|
104
|
-
- '
|
|
105
|
-
- '**/*.css'
|
|
104
|
+
- '**/*.scss'
|
|
106
105
|
rules:
|
|
107
|
-
at-rule-disallowed-list:
|
|
106
|
+
at-rule-disallowed-list:
|
|
107
|
+
- import
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
-
The
|
|
110
|
+
The SCSS file, for example `at-rule-disallowed-list.scss`:
|
|
111
111
|
|
|
112
|
-
```
|
|
112
|
+
```scss
|
|
113
113
|
@import 'test.css';
|
|
114
114
|
```
|
|
115
115
|
|
|
@@ -119,17 +119,24 @@ Verifying the `at-rule-disallowed-list` rule configuration:
|
|
|
119
119
|
import { ConfigVerifier } from '@jhae/stylelint-config-verifier';
|
|
120
120
|
|
|
121
121
|
new ConfigVerifier().verify('at-rule-disallowed-list', {
|
|
122
|
-
name: '
|
|
122
|
+
name: 'Disallow @import rule in SCSS files',
|
|
123
123
|
|
|
124
124
|
// Pass the file instead of inline code.
|
|
125
|
-
file: 'at-rule-disallowed-list.
|
|
125
|
+
file: 'at-rule-disallowed-list.scss',
|
|
126
|
+
|
|
127
|
+
expect: {
|
|
128
|
+
errored: true,
|
|
129
|
+
messages: ['Unexpected at-rule "@import"'],
|
|
130
|
+
severities: ['error'],
|
|
131
|
+
},
|
|
126
132
|
});
|
|
127
133
|
```
|
|
128
134
|
|
|
129
135
|
### Specifying the Stylelint configuration file
|
|
130
136
|
|
|
131
|
-
By default, the
|
|
132
|
-
|
|
137
|
+
By default, the Stylelint configuration file is detected automatically as described in
|
|
138
|
+
the [Stylelint documentation](https://stylelint.io/user-guide/configure). If needed, you can override this behavior by
|
|
139
|
+
passing the path to the configuration file to the constructor.
|
|
133
140
|
|
|
134
141
|
```javascript
|
|
135
142
|
import { ConfigVerifier } from '@jhae/stylelint-config-verifier';
|
|
@@ -11,7 +11,7 @@ const stylelint_1 = __importDefault(require("stylelint"));
|
|
|
11
11
|
* the expected result. The expected result contains the expected error status, messages, and severities.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
|
-
* ```
|
|
14
|
+
* ```javascript
|
|
15
15
|
* new ConfigVerifier().verify(
|
|
16
16
|
* 'at-rule-disallowed-list',
|
|
17
17
|
* {
|
|
@@ -28,7 +28,7 @@ const stylelint_1 = __importDefault(require("stylelint"));
|
|
|
28
28
|
* code: '@use "test.scss";',
|
|
29
29
|
* },
|
|
30
30
|
* );
|
|
31
|
-
*
|
|
31
|
+
* ```
|
|
32
32
|
*/
|
|
33
33
|
class ConfigVerifier {
|
|
34
34
|
configFile;
|
|
@@ -49,16 +49,16 @@ class ConfigVerifier {
|
|
|
49
49
|
/**
|
|
50
50
|
* Creates a new `ConfigVerifier` object.
|
|
51
51
|
*
|
|
52
|
-
* @param {string} configFile The path to the Stylelint config file whose rules should be verified
|
|
52
|
+
* @param {string | undefined} configFile - The path to the Stylelint config file whose rules should be verified
|
|
53
53
|
*/
|
|
54
|
-
constructor(configFile
|
|
54
|
+
constructor(configFile) {
|
|
55
55
|
this.configFile = configFile;
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Verifies a rule configuration.
|
|
59
59
|
*
|
|
60
|
-
* @param {string} ruleName The name of the rule
|
|
61
|
-
* @param {TestCase[]} testCases The test cases
|
|
60
|
+
* @param {string} ruleName - The name of the rule
|
|
61
|
+
* @param {TestCase[]} testCases - The test cases
|
|
62
62
|
*/
|
|
63
63
|
verify(ruleName, ...testCases) {
|
|
64
64
|
describe(`Rule '${ruleName}'`, () => {
|
|
@@ -76,9 +76,11 @@ class ConfigVerifier {
|
|
|
76
76
|
*
|
|
77
77
|
* @internal
|
|
78
78
|
*
|
|
79
|
-
* @param {TestCase} testCase The test case
|
|
79
|
+
* @param {TestCase} testCase - The test case
|
|
80
80
|
*
|
|
81
|
-
* @
|
|
81
|
+
* @returns {Promise<LinterResult>} A Promise that resolves to the linter result
|
|
82
|
+
*
|
|
83
|
+
* @throws {Error} If both `file` and `code` are defined or undefined
|
|
82
84
|
*/
|
|
83
85
|
getLinterResult({ file, code }) {
|
|
84
86
|
if ([file, code].filter((value) => value === undefined).length !== 1) {
|
|
@@ -95,10 +97,10 @@ class ConfigVerifier {
|
|
|
95
97
|
*
|
|
96
98
|
* @internal
|
|
97
99
|
*
|
|
98
|
-
* @param {string} ruleName The name of the rule
|
|
99
|
-
* @param {LinterResult} linterResult The linter result
|
|
100
|
+
* @param {string} ruleName - The name of the rule
|
|
101
|
+
* @param {LinterResult} linterResult - The linter result
|
|
100
102
|
*
|
|
101
|
-
* @
|
|
103
|
+
* @returns {Warning[]} The warnings for the rule
|
|
102
104
|
*/
|
|
103
105
|
getWarnings(ruleName, { results: lintResults }) {
|
|
104
106
|
return lintResults
|
|
@@ -111,9 +113,9 @@ class ConfigVerifier {
|
|
|
111
113
|
*
|
|
112
114
|
* @internal
|
|
113
115
|
*
|
|
114
|
-
* @param {Warning[]} warnings The lint warnings
|
|
116
|
+
* @param {Warning[]} warnings - The lint warnings
|
|
115
117
|
*
|
|
116
|
-
* @
|
|
118
|
+
* @returns {boolean} True if the warnings contain an error, otherwise false
|
|
117
119
|
*/
|
|
118
120
|
getErrored(warnings) {
|
|
119
121
|
return this.getSeverities(warnings).some((severity) => severity === 'error');
|
|
@@ -123,9 +125,9 @@ class ConfigVerifier {
|
|
|
123
125
|
*
|
|
124
126
|
* @internal
|
|
125
127
|
*
|
|
126
|
-
* @param {Warning[]} warnings The lint warnings
|
|
128
|
+
* @param {Warning[]} warnings - The lint warnings
|
|
127
129
|
*
|
|
128
|
-
* @
|
|
130
|
+
* @returns {string[]} The messages of the warnings
|
|
129
131
|
*/
|
|
130
132
|
getMessages(warnings) {
|
|
131
133
|
return warnings.map(({ text }) => text);
|
|
@@ -135,12 +137,13 @@ class ConfigVerifier {
|
|
|
135
137
|
*
|
|
136
138
|
* @internal
|
|
137
139
|
*
|
|
138
|
-
* @param {Warning[]} warnings The lint warnings
|
|
140
|
+
* @param {Warning[]} warnings - The lint warnings
|
|
139
141
|
*
|
|
140
|
-
* @
|
|
142
|
+
* @returns {Severity[]} The severities of the warnings
|
|
141
143
|
*/
|
|
142
144
|
getSeverities(warnings) {
|
|
143
145
|
return warnings.map(({ severity }) => severity);
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
148
|
exports.ConfigVerifier = ConfigVerifier;
|
|
149
|
+
exports.default = ConfigVerifier;
|
|
@@ -5,7 +5,7 @@ import stylelint from 'stylelint';
|
|
|
5
5
|
* the expected result. The expected result contains the expected error status, messages, and severities.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* ```
|
|
8
|
+
* ```javascript
|
|
9
9
|
* new ConfigVerifier().verify(
|
|
10
10
|
* 'at-rule-disallowed-list',
|
|
11
11
|
* {
|
|
@@ -22,7 +22,7 @@ import stylelint from 'stylelint';
|
|
|
22
22
|
* code: '@use "test.scss";',
|
|
23
23
|
* },
|
|
24
24
|
* );
|
|
25
|
-
*
|
|
25
|
+
* ```
|
|
26
26
|
*/
|
|
27
27
|
export class ConfigVerifier {
|
|
28
28
|
configFile;
|
|
@@ -43,16 +43,16 @@ export class ConfigVerifier {
|
|
|
43
43
|
/**
|
|
44
44
|
* Creates a new `ConfigVerifier` object.
|
|
45
45
|
*
|
|
46
|
-
* @param {string} configFile The path to the Stylelint config file whose rules should be verified
|
|
46
|
+
* @param {string | undefined} configFile - The path to the Stylelint config file whose rules should be verified
|
|
47
47
|
*/
|
|
48
|
-
constructor(configFile
|
|
48
|
+
constructor(configFile) {
|
|
49
49
|
this.configFile = configFile;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Verifies a rule configuration.
|
|
53
53
|
*
|
|
54
|
-
* @param {string} ruleName The name of the rule
|
|
55
|
-
* @param {TestCase[]} testCases The test cases
|
|
54
|
+
* @param {string} ruleName - The name of the rule
|
|
55
|
+
* @param {TestCase[]} testCases - The test cases
|
|
56
56
|
*/
|
|
57
57
|
verify(ruleName, ...testCases) {
|
|
58
58
|
describe(`Rule '${ruleName}'`, () => {
|
|
@@ -70,9 +70,11 @@ export class ConfigVerifier {
|
|
|
70
70
|
*
|
|
71
71
|
* @internal
|
|
72
72
|
*
|
|
73
|
-
* @param {TestCase} testCase The test case
|
|
73
|
+
* @param {TestCase} testCase - The test case
|
|
74
74
|
*
|
|
75
|
-
* @
|
|
75
|
+
* @returns {Promise<LinterResult>} A Promise that resolves to the linter result
|
|
76
|
+
*
|
|
77
|
+
* @throws {Error} If both `file` and `code` are defined or undefined
|
|
76
78
|
*/
|
|
77
79
|
getLinterResult({ file, code }) {
|
|
78
80
|
if ([file, code].filter((value) => value === undefined).length !== 1) {
|
|
@@ -89,10 +91,10 @@ export class ConfigVerifier {
|
|
|
89
91
|
*
|
|
90
92
|
* @internal
|
|
91
93
|
*
|
|
92
|
-
* @param {string} ruleName The name of the rule
|
|
93
|
-
* @param {LinterResult} linterResult The linter result
|
|
94
|
+
* @param {string} ruleName - The name of the rule
|
|
95
|
+
* @param {LinterResult} linterResult - The linter result
|
|
94
96
|
*
|
|
95
|
-
* @
|
|
97
|
+
* @returns {Warning[]} The warnings for the rule
|
|
96
98
|
*/
|
|
97
99
|
getWarnings(ruleName, { results: lintResults }) {
|
|
98
100
|
return lintResults
|
|
@@ -105,9 +107,9 @@ export class ConfigVerifier {
|
|
|
105
107
|
*
|
|
106
108
|
* @internal
|
|
107
109
|
*
|
|
108
|
-
* @param {Warning[]} warnings The lint warnings
|
|
110
|
+
* @param {Warning[]} warnings - The lint warnings
|
|
109
111
|
*
|
|
110
|
-
* @
|
|
112
|
+
* @returns {boolean} True if the warnings contain an error, otherwise false
|
|
111
113
|
*/
|
|
112
114
|
getErrored(warnings) {
|
|
113
115
|
return this.getSeverities(warnings).some((severity) => severity === 'error');
|
|
@@ -117,9 +119,9 @@ export class ConfigVerifier {
|
|
|
117
119
|
*
|
|
118
120
|
* @internal
|
|
119
121
|
*
|
|
120
|
-
* @param {Warning[]} warnings The lint warnings
|
|
122
|
+
* @param {Warning[]} warnings - The lint warnings
|
|
121
123
|
*
|
|
122
|
-
* @
|
|
124
|
+
* @returns {string[]} The messages of the warnings
|
|
123
125
|
*/
|
|
124
126
|
getMessages(warnings) {
|
|
125
127
|
return warnings.map(({ text }) => text);
|
|
@@ -129,11 +131,12 @@ export class ConfigVerifier {
|
|
|
129
131
|
*
|
|
130
132
|
* @internal
|
|
131
133
|
*
|
|
132
|
-
* @param {Warning[]} warnings The lint warnings
|
|
134
|
+
* @param {Warning[]} warnings - The lint warnings
|
|
133
135
|
*
|
|
134
|
-
* @
|
|
136
|
+
* @returns {Severity[]} The severities of the warnings
|
|
135
137
|
*/
|
|
136
138
|
getSeverities(warnings) {
|
|
137
139
|
return warnings.map(({ severity }) => severity);
|
|
138
140
|
}
|
|
139
141
|
}
|
|
142
|
+
export default ConfigVerifier;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jhae/stylelint-config-verifier",
|
|
3
3
|
"description": "A Stylelint configuration tester for Jest that helps you verify your defined rules.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "JHAE",
|
|
@@ -15,38 +15,46 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"main": "./dist/cjs/config-verifier.js",
|
|
17
17
|
"module": "./dist/esm/config-verifier.js",
|
|
18
|
+
"types": "./types/index.d.ts",
|
|
18
19
|
"exports": {
|
|
19
20
|
"types": "./types/index.d.ts",
|
|
20
21
|
"require": "./dist/cjs/config-verifier.js",
|
|
21
22
|
"default": "./dist/esm/config-verifier.js"
|
|
22
23
|
},
|
|
24
|
+
"files": [
|
|
25
|
+
"./dist/",
|
|
26
|
+
"./types/"
|
|
27
|
+
],
|
|
23
28
|
"scripts": {
|
|
24
|
-
"build": "
|
|
25
|
-
"build:
|
|
29
|
+
"build": "npm run-script build:package && npm run-script build:types",
|
|
30
|
+
"build:package": "./bin/build-package",
|
|
31
|
+
"build:types": "./bin/build-types",
|
|
26
32
|
"fix": "npm run-script fix:prettier && npm run-script fix:eslint",
|
|
27
33
|
"fix:eslint": "eslint --fix .",
|
|
28
|
-
"fix:prettier": "prettier
|
|
34
|
+
"fix:prettier": "prettier --write .",
|
|
29
35
|
"lint": "npm run-script lint:prettier && npm run-script lint:eslint",
|
|
30
36
|
"lint:eslint": "eslint .",
|
|
31
|
-
"lint:prettier": "prettier
|
|
37
|
+
"lint:prettier": "prettier --check .",
|
|
38
|
+
"prepack": "npm run-script build",
|
|
32
39
|
"test": "jest",
|
|
33
40
|
"test:coverage": "npm run-script test -- --coverage",
|
|
34
41
|
"test:watch": "npm run-script test -- --watchAll",
|
|
35
42
|
"test:watch:coverage": "npm run-script test:watch -- --coverage"
|
|
36
43
|
},
|
|
37
44
|
"devDependencies": {
|
|
38
|
-
"@eslint/js": "^9.
|
|
39
|
-
"@types/jest": "^
|
|
40
|
-
"eslint": "^9.
|
|
41
|
-
"eslint-config-prettier": "^10.
|
|
42
|
-
"eslint-plugin-prettier": "^5.
|
|
43
|
-
"
|
|
45
|
+
"@eslint/js": "^9.0",
|
|
46
|
+
"@types/jest": "^30.0",
|
|
47
|
+
"eslint": "^9.0",
|
|
48
|
+
"eslint-config-prettier": "^10.0",
|
|
49
|
+
"eslint-plugin-prettier": "^5.1",
|
|
50
|
+
"jest": "^30.0",
|
|
51
|
+
"prettier": "^3.0",
|
|
52
|
+
"stylelint": "^16.0",
|
|
44
53
|
"ts-jest": "^29.2",
|
|
45
|
-
"typescript": "^5.
|
|
46
|
-
"typescript-eslint": "^8.
|
|
54
|
+
"typescript": "^5.0",
|
|
55
|
+
"typescript-eslint": "^8.42"
|
|
47
56
|
},
|
|
48
57
|
"peerDependencies": {
|
|
49
|
-
"jest": "^29.0",
|
|
50
58
|
"stylelint": "^16.0"
|
|
51
59
|
},
|
|
52
60
|
"keywords": [
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { TestCase } from './type';
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* The `ConfigVerifier` class verifies the rules of a Stylelint configuration. It runs Stylelint for a given test case
|
|
5
4
|
* and compares the linter result with the expected result. The test case contains the code that should be linted and
|
|
6
5
|
* the expected result. The expected result contains the expected error status, messages, and severities.
|
|
7
6
|
*
|
|
8
7
|
* @example
|
|
9
|
-
* ```
|
|
8
|
+
* ```javascript
|
|
10
9
|
* new ConfigVerifier().verify(
|
|
11
10
|
* 'at-rule-disallowed-list',
|
|
12
11
|
* {
|
|
@@ -23,21 +22,21 @@ import type { TestCase } from './type';
|
|
|
23
22
|
* code: '@use "test.scss";',
|
|
24
23
|
* },
|
|
25
24
|
* );
|
|
26
|
-
*
|
|
25
|
+
* ```
|
|
27
26
|
*/
|
|
28
27
|
export declare class ConfigVerifier {
|
|
29
28
|
/**
|
|
30
29
|
* Creates a new `ConfigVerifier` object.
|
|
31
30
|
*
|
|
32
|
-
* @param {string} configFile The path to the Stylelint config file whose rules should be verified
|
|
31
|
+
* @param {string | undefined} configFile - The path to the Stylelint config file whose rules should be verified
|
|
33
32
|
*/
|
|
34
|
-
constructor(configFile?: string);
|
|
35
|
-
|
|
33
|
+
constructor(configFile?: string | undefined);
|
|
36
34
|
/**
|
|
37
35
|
* Verifies a rule configuration.
|
|
38
36
|
*
|
|
39
|
-
* @param {string} ruleName The name of the rule
|
|
40
|
-
* @param {TestCase[]} testCases The test cases
|
|
37
|
+
* @param {string} ruleName - The name of the rule
|
|
38
|
+
* @param {TestCase[]} testCases - The test cases
|
|
41
39
|
*/
|
|
42
40
|
verify(ruleName: string, ...testCases: TestCase[]): void;
|
|
43
41
|
}
|
|
42
|
+
export default ConfigVerifier;
|