@jhae/stylelint-config-verifier 1.3.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
@@ -134,8 +134,9 @@ new ConfigVerifier().verify('at-rule-disallowed-list', {
134
134
 
135
135
  ### Specifying the Stylelint configuration file
136
136
 
137
- By default, the config verifier looks for a `.stylelintrc.yaml` configuration file. If a different location or file name
138
- is used, the path to it can be specified as a constructor argument.
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.
139
140
 
140
141
  ```javascript
141
142
  import { ConfigVerifier } from '@jhae/stylelint-config-verifier';
@@ -143,14 +144,6 @@ import { ConfigVerifier } from '@jhae/stylelint-config-verifier';
143
144
  new ConfigVerifier('path/to/stylelint.config.js').verify();
144
145
  ```
145
146
 
146
- ### Importing into CommonJS
147
-
148
- ```javascript
149
- const { ConfigVerifier } = require('@jhae/stylelint-config-verifier');
150
-
151
- new ConfigVerifier().verify();
152
- ```
153
-
154
147
  ---
155
148
 
156
149
  Check out the [Standard SCSS Stylelint Config](https://github.com/jhae-de/stylelint-config-standard-scss) tests for more
@@ -43,9 +43,9 @@ 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 = '.stylelintrc.yaml') {
48
+ constructor(configFile) {
49
49
  this.configFile = configFile;
50
50
  }
51
51
  /**
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.3.0",
4
+ "version": "2.0.0",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "JHAE",
@@ -13,24 +13,24 @@
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
  },
20
+ "files": [
21
+ "./dist/",
22
+ "./types/"
23
+ ],
24
24
  "scripts": {
25
25
  "build": "npm run-script build:package && npm run-script build:types",
26
26
  "build:package": "./bin/build-package",
27
27
  "build:types": "./bin/build-types",
28
28
  "fix": "npm run-script fix:prettier && npm run-script fix:eslint",
29
29
  "fix:eslint": "eslint --fix .",
30
- "fix:prettier": "prettier . --write",
30
+ "fix:prettier": "prettier --write .",
31
31
  "lint": "npm run-script lint:prettier && npm run-script lint:eslint",
32
32
  "lint:eslint": "eslint .",
33
- "lint:prettier": "prettier . --check",
33
+ "lint:prettier": "prettier --check .",
34
34
  "prepack": "npm run-script build",
35
35
  "test": "jest",
36
36
  "test:coverage": "npm run-script test -- --coverage",
@@ -45,13 +45,16 @@
45
45
  "eslint-plugin-prettier": "^5.1",
46
46
  "jest": "^30.0",
47
47
  "prettier": "^3.0",
48
- "stylelint": "^16.0",
48
+ "stylelint": "^17.0",
49
49
  "ts-jest": "^29.2",
50
50
  "typescript": "^5.0",
51
- "typescript-eslint": "^8.0"
51
+ "typescript-eslint": "^8.42"
52
52
  },
53
53
  "peerDependencies": {
54
- "stylelint": "^16.0"
54
+ "stylelint": "^17.0"
55
+ },
56
+ "engines": {
57
+ "node": ">=20.0"
55
58
  },
56
59
  "keywords": [
57
60
  "config",
@@ -28,9 +28,9 @@ export declare class ConfigVerifier {
28
28
  /**
29
29
  * Creates a new `ConfigVerifier` object.
30
30
  *
31
- * @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
32
32
  */
33
- constructor(configFile?: string);
33
+ constructor(configFile?: string | undefined);
34
34
  /**
35
35
  * Verifies a rule configuration.
36
36
  *
@@ -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} configFile - The path to the Stylelint config file whose rules should be verified
53
- */
54
- constructor(configFile = '.stylelintrc.yaml') {
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
- }