@jhae/stylelint-config-verifier 1.4.0 → 2.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 CHANGED
@@ -144,14 +144,6 @@ import { ConfigVerifier } from '@jhae/stylelint-config-verifier';
144
144
  new ConfigVerifier('path/to/stylelint.config.js').verify();
145
145
  ```
146
146
 
147
- ### Importing into CommonJS
148
-
149
- ```javascript
150
- const { ConfigVerifier } = require('@jhae/stylelint-config-verifier');
151
-
152
- new ConfigVerifier().verify();
153
- ```
154
-
155
147
  ---
156
148
 
157
149
  Check out the [Standard SCSS Stylelint Config](https://github.com/jhae-de/stylelint-config-standard-scss) tests for more
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.0",
4
+ "version": "2.0.0",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "JHAE",
@@ -13,13 +13,9 @@
13
13
  "type": "git"
14
14
  },
15
15
  "type": "module",
16
- "main": "./dist/cjs/config-verifier.js",
17
- "module": "./dist/esm/config-verifier.js",
18
- "types": "./types/index.d.ts",
19
16
  "exports": {
20
17
  "types": "./types/index.d.ts",
21
- "require": "./dist/cjs/config-verifier.js",
22
- "default": "./dist/esm/config-verifier.js"
18
+ "default": "./dist/config-verifier.js"
23
19
  },
24
20
  "files": [
25
21
  "./dist/",
@@ -49,13 +45,16 @@
49
45
  "eslint-plugin-prettier": "^5.1",
50
46
  "jest": "^30.0",
51
47
  "prettier": "^3.0",
52
- "stylelint": "^16.0",
48
+ "stylelint": "^17.0",
53
49
  "ts-jest": "^29.2",
54
50
  "typescript": "^5.0",
55
51
  "typescript-eslint": "^8.42"
56
52
  },
57
53
  "peerDependencies": {
58
- "stylelint": "^16.0"
54
+ "stylelint": "^17.0"
55
+ },
56
+ "engines": {
57
+ "node": ">=20.0"
59
58
  },
60
59
  "keywords": [
61
60
  "config",
@@ -1,149 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ConfigVerifier = void 0;
7
- const stylelint_1 = __importDefault(require("stylelint"));
8
- /**
9
- * The `ConfigVerifier` class verifies the rules of a Stylelint configuration. It runs Stylelint for a given test case
10
- * and compares the linter result with the expected result. The test case contains the code that should be linted and
11
- * the expected result. The expected result contains the expected error status, messages, and severities.
12
- *
13
- * @example
14
- * ```javascript
15
- * new ConfigVerifier().verify(
16
- * 'at-rule-disallowed-list',
17
- * {
18
- * name: 'Disallow @debug rule',
19
- * code: '@debug "";',
20
- * expect: {
21
- * errored: true,
22
- * messages: ['Unexpected at-rule "debug"'],
23
- * severities: ['error'],
24
- * },
25
- * },
26
- * {
27
- * name: 'Allow @use rule',
28
- * code: '@use "test.scss";',
29
- * },
30
- * );
31
- * ```
32
- */
33
- class ConfigVerifier {
34
- configFile;
35
- /**
36
- * The default test case expectation
37
- *
38
- * This expectation occurs if Stylelint reports no problems and is used if no expectation was defined in a test case.
39
- *
40
- * @type {TestCaseExpectation}
41
- *
42
- * @internal
43
- */
44
- defaultExpectation = {
45
- errored: false,
46
- messages: [],
47
- severities: [],
48
- };
49
- /**
50
- * Creates a new `ConfigVerifier` object.
51
- *
52
- * @param {string | undefined} configFile - The path to the Stylelint config file whose rules should be verified
53
- */
54
- constructor(configFile) {
55
- this.configFile = configFile;
56
- }
57
- /**
58
- * Verifies a rule configuration.
59
- *
60
- * @param {string} ruleName - The name of the rule
61
- * @param {TestCase[]} testCases - The test cases
62
- */
63
- verify(ruleName, ...testCases) {
64
- describe(`Rule '${ruleName}'`, () => {
65
- test.each(testCases)('$name', async (testCase) => {
66
- const warnings = this.getWarnings(ruleName, await this.getLinterResult(testCase));
67
- const { expect: expectation = this.defaultExpectation } = testCase;
68
- expect(this.getErrored(warnings)).toBe(expectation.errored);
69
- expect(this.getMessages(warnings)).toStrictEqual(expectation.messages.map((message) => `${message} (${ruleName})`));
70
- expect(this.getSeverities(warnings)).toStrictEqual(expectation.severities);
71
- });
72
- });
73
- }
74
- /**
75
- * Runs Stylelint for the given test case and returns a Promise that resolves to the linter result.
76
- *
77
- * @internal
78
- *
79
- * @param {TestCase} testCase - The test case
80
- *
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
84
- */
85
- getLinterResult({ file, code }) {
86
- if ([file, code].filter((value) => value === undefined).length !== 1) {
87
- throw new Error('Though both "file" and "code" are optional, you must have one and cannot have both.');
88
- }
89
- return stylelint_1.default.lint({
90
- configFile: this.configFile,
91
- files: file,
92
- code,
93
- });
94
- }
95
- /**
96
- * Returns the warnings for a rule from the given linter result.
97
- *
98
- * @internal
99
- *
100
- * @param {string} ruleName - The name of the rule
101
- * @param {LinterResult} linterResult - The linter result
102
- *
103
- * @returns {Warning[]} The warnings for the rule
104
- */
105
- getWarnings(ruleName, { results: lintResults }) {
106
- return lintResults
107
- .map(({ warnings }) => warnings)
108
- .reduce((previous, current) => previous.concat(current), [])
109
- .filter((warning) => warning.rule === ruleName);
110
- }
111
- /**
112
- * Returns true if the given lint warnings contain an error, otherwise false.
113
- *
114
- * @internal
115
- *
116
- * @param {Warning[]} warnings - The lint warnings
117
- *
118
- * @returns {boolean} True if the warnings contain an error, otherwise false
119
- */
120
- getErrored(warnings) {
121
- return this.getSeverities(warnings).some((severity) => severity === 'error');
122
- }
123
- /**
124
- * Returns the messages of the given lint warnings.
125
- *
126
- * @internal
127
- *
128
- * @param {Warning[]} warnings - The lint warnings
129
- *
130
- * @returns {string[]} The messages of the warnings
131
- */
132
- getMessages(warnings) {
133
- return warnings.map(({ text }) => text);
134
- }
135
- /**
136
- * Returns the severities of the given lint warnings.
137
- *
138
- * @internal
139
- *
140
- * @param {Warning[]} warnings - The lint warnings
141
- *
142
- * @returns {Severity[]} The severities of the warnings
143
- */
144
- getSeverities(warnings) {
145
- return warnings.map(({ severity }) => severity);
146
- }
147
- }
148
- exports.ConfigVerifier = ConfigVerifier;
149
- exports.default = ConfigVerifier;
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }