@jhae/stylelint-config-verifier 1.1.0 → 1.3.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
- ![Version](https://img.shields.io/npm/v/%40jhae/stylelint-config-verifier?label=Version)
2
- ![License](https://img.shields.io/github/license/jhae-de/stylelint-config-verifier?label=License&color=lightgrey)
3
- ![Tests](https://img.shields.io/github/actions/workflow/status/jhae-de/stylelint-config-verifier/analyze.yaml?label=Tests)
4
- ![Coverage](https://img.shields.io/codecov/c/github/jhae-de/stylelint-config-verifier/main?label=Coverage)
1
+ ![Version](https://img.shields.io/npm/v/%40jhae/stylelint-config-verifier?label=Version&labelColor=%23404850&color=blue)
2
+ ![License](https://img.shields.io/github/license/jhae-de/stylelint-config-verifier?label=License&labelColor=%23404850&color=blue)
3
+ ![Downloads](https://img.shields.io/npm/dt/%40jhae%2Fstylelint-config-verifier?label=Downloads&labelColor=%23404850&color=blue)
4
+ ![Tests](https://img.shields.io/github/actions/workflow/status/jhae-de/stylelint-config-verifier/analyze.yaml?label=Tests&labelColor=%23404850)
5
+ ![Coverage](https://img.shields.io/codecov/c/github/jhae-de/stylelint-config-verifier/main?label=Coverage&labelColor=%23404850)
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
- - '*.css'
105
- - '**/*.css'
104
+ - '**/*.scss'
106
105
  rules:
107
- at-rule-disallowed-list: null
106
+ at-rule-disallowed-list:
107
+ - import
108
108
  ```
109
109
 
110
- The CSS file, for example `at-rule-disallowed-list.css`:
110
+ The SCSS file, for example `at-rule-disallowed-list.scss`:
111
111
 
112
- ```css
112
+ ```scss
113
113
  @import 'test.css';
114
114
  ```
115
115
 
@@ -119,10 +119,16 @@ 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: 'Allow @import rule in CSS files',
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.css',
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
 
@@ -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
- * ```typescript
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,7 +49,7 @@ 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} configFile - The path to the Stylelint config file whose rules should be verified
53
53
  */
54
54
  constructor(configFile = '.stylelintrc.yaml') {
55
55
  this.configFile = configFile;
@@ -57,8 +57,8 @@ class ConfigVerifier {
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
- * @return {Promise<LinterResult>}
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
- * @return {Warning[]}
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
- * @return {boolean}
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
- * @return {string[]}
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
- * @return {Severity[]}
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
- * ```typescript
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,7 +43,7 @@ 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} configFile - The path to the Stylelint config file whose rules should be verified
47
47
  */
48
48
  constructor(configFile = '.stylelintrc.yaml') {
49
49
  this.configFile = configFile;
@@ -51,8 +51,8 @@ export class ConfigVerifier {
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
- * @return {Promise<LinterResult>}
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
- * @return {Warning[]}
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
- * @return {boolean}
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
- * @return {string[]}
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
- * @return {Severity[]}
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.1.0",
4
+ "version": "1.3.0",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "JHAE",
@@ -15,35 +15,42 @@
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
- "types": "./types/config-verifier.d.ts",
20
+ "types": "./types/index.d.ts",
20
21
  "require": "./dist/cjs/config-verifier.js",
21
22
  "default": "./dist/esm/config-verifier.js"
22
23
  },
23
24
  "scripts": {
24
- "build": "./bin/build.sh",
25
- "build:types": "./bin/build-types.sh",
25
+ "build": "npm run-script build:package && npm run-script build:types",
26
+ "build:package": "./bin/build-package",
27
+ "build:types": "./bin/build-types",
28
+ "fix": "npm run-script fix:prettier && npm run-script fix:eslint",
29
+ "fix:eslint": "eslint --fix .",
30
+ "fix:prettier": "prettier . --write",
26
31
  "lint": "npm run-script lint:prettier && npm run-script lint:eslint",
27
32
  "lint:eslint": "eslint .",
28
33
  "lint:prettier": "prettier . --check",
34
+ "prepack": "npm run-script build",
29
35
  "test": "jest",
30
36
  "test:coverage": "npm run-script test -- --coverage",
31
37
  "test:watch": "npm run-script test -- --watchAll",
32
38
  "test:watch:coverage": "npm run-script test:watch -- --coverage"
33
39
  },
34
40
  "devDependencies": {
35
- "@eslint/js": "^9.21",
36
- "@types/jest": "^29.5",
37
- "eslint": "^9.21",
41
+ "@eslint/js": "^9.0",
42
+ "@types/jest": "^30.0",
43
+ "eslint": "^9.0",
38
44
  "eslint-config-prettier": "^10.0",
39
- "eslint-plugin-prettier": "^5.2",
40
- "prettier": "^3.5",
45
+ "eslint-plugin-prettier": "^5.1",
46
+ "jest": "^30.0",
47
+ "prettier": "^3.0",
48
+ "stylelint": "^16.0",
41
49
  "ts-jest": "^29.2",
42
- "typescript": "^5.7",
43
- "typescript-eslint": "^8.24"
50
+ "typescript": "^5.0",
51
+ "typescript-eslint": "^8.0"
44
52
  },
45
53
  "peerDependencies": {
46
- "jest": "^29.0",
47
54
  "stylelint": "^16.0"
48
55
  },
49
56
  "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
- * ```typescript
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} configFile - The path to the Stylelint config file whose rules should be verified
33
32
  */
34
33
  constructor(configFile?: string);
35
-
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;
@@ -0,0 +1,2 @@
1
+ export type { TestCase, TestCaseExpectation } from './type';
2
+ export { ConfigVerifier } from './config-verifier.d.ts';
@@ -1,5 +1,4 @@
1
1
  import type { Severity } from 'stylelint';
2
-
3
2
  export type TestCaseExpectation = {
4
3
  errored: boolean;
5
4
  messages: string[];
@@ -1,5 +1,4 @@
1
1
  import type { TestCaseExpectation } from './index';
2
-
3
2
  export type TestCase = {
4
3
  name: string;
5
4
  file?: string;