Skip to content

Commit f21e090

Browse files
authored
fix: add type tests (#16)
* fix: add type tests * match formatting to Prettier 3.4
1 parent 33fb3b8 commit f21e090

14 files changed

+86
-37
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#### Prerequisites checklist
88

9-
- [ ] I have read the [contributing guidelines](https://github.com/eslint/eslint/blob/HEAD/CONTRIBUTING.md).
9+
- [ ] I have read the [contributing guidelines](https://github.com/eslint/eslint/blob/HEAD/CONTRIBUTING.md).
1010

1111
<!--
1212
Please ensure your pull request is ready:

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ jobs:
4545
run: npm install
4646
- name: Run tests
4747
run: npm run test
48+
test_types:
49+
name: Test Types
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v4
53+
- name: Setup Node.js
54+
uses: actions/setup-node@v4
55+
with:
56+
node-version: "lts/*"
57+
- name: Install dependencies
58+
run: npm install
59+
- name: Build
60+
run: npm run build
61+
- name: Check Types
62+
run: npm run test:types
4863
jsr_test:
4964
name: Verify JSR Publish
5065
runs-on: ubuntu-latest

docs/rules/no-duplicate-imports.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ If you aren't concerned with duplicate `@import` rules, you can safely disable t
3838

3939
## Prior Art
4040

41-
- [`no-duplicate-at-import-rules`](https://stylelint.io/user-guide/rules/no-duplicate-at-import-rules)
41+
- [`no-duplicate-at-import-rules`](https://stylelint.io/user-guide/rules/no-duplicate-at-import-rules)

docs/rules/no-empty-blocks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ If you aren't concerned with empty blocks, you can safely disable this rule.
5151

5252
## Prior Art
5353

54-
- [empty-rules](https://github.com/CSSLint/csslint/wiki/Disallow-empty-rules)
55-
- [`block-no-empty`](https://stylelint.io/user-guide/rules/block-no-empty)
54+
- [empty-rules](https://github.com/CSSLint/csslint/wiki/Disallow-empty-rules)
55+
- [`block-no-empty`](https://stylelint.io/user-guide/rules/block-no-empty)

docs/rules/no-invalid-at-rules.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ Disallow invalid at-rules.
66

77
CSS contains a number of at-rules, each beginning with a `@`, that perform various operations. Some common at-rules include:
88

9-
- `@import`
10-
- `@media`
11-
- `@font-face`
12-
- `@keyframes`
13-
- `@supports`
14-
- `@namespace`
15-
- `@page`
16-
- `@charset`
9+
- `@import`
10+
- `@media`
11+
- `@font-face`
12+
- `@keyframes`
13+
- `@supports`
14+
- `@namespace`
15+
- `@page`
16+
- `@charset`
1717

1818
It's important to use a known at-rule because unknown at-rules cause the browser to ignore the entire block, including any rules contained within. For example:
1919

@@ -40,10 +40,10 @@ Here, `--main-bg-color` is the prelude for `@property` while `syntax`, `inherits
4040

4141
This rule warns when it finds a CSS at-rule that is unknown or invalid according to the CSS specification. As such, the rule warns for the following problems:
4242

43-
- An unknown at-rule
44-
- An invalid prelude for a known at-rule
45-
- An unknown descriptor for a known at-rule
46-
- An invalid descriptor value for a known at-rule
43+
- An unknown at-rule
44+
- An invalid prelude for a known at-rule
45+
- An unknown descriptor for a known at-rule
46+
- An invalid descriptor value for a known at-rule
4747

4848
The at-rule data is provided via the [CSSTree](https://github.com/csstree/csstree) project.
4949

@@ -77,4 +77,4 @@ If you are purposely using at-rules that aren't part of the CSS specification, t
7777

7878
## Prior Art
7979

80-
- [`at-rule-no-unknown`](https://stylelint.io/user-guide/rules/at-rule-no-unknown)
80+
- [`at-rule-no-unknown`](https://stylelint.io/user-guide/rules/at-rule-no-unknown)

docs/rules/no-invalid-properties.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ If you aren't concerned with invalid properties, then you can safely disable thi
4848

4949
## Prior Art
5050

51-
- [`declaration-property-value-no-unknown`](https://stylelint.io/user-guide/rules/declaration-property-value-no-unknown/)
51+
- [`declaration-property-value-no-unknown`](https://stylelint.io/user-guide/rules/declaration-property-value-no-unknown/)
5252

53-
- [`property-no-unknown`](https://stylelint.io/user-guide/rules/property-no-unknown)
53+
- [`property-no-unknown`](https://stylelint.io/user-guide/rules/property-no-unknown)

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"fmt": "prettier --write .",
5858
"fmt:check": "prettier --check .",
5959
"test": "mocha tests/**/*.js",
60-
"test:coverage": "c8 npm test"
60+
"test:coverage": "c8 npm test",
61+
"test:types": "tsc -p tests/types/tsconfig.json"
6162
},
6263
"keywords": [
6364
"eslint",
@@ -84,7 +85,7 @@
8485
"lint-staged": "^15.2.7",
8586
"mdast-util-from-markdown": "^2.0.2",
8687
"mocha": "^10.4.0",
87-
"prettier": "^3.3.2",
88+
"prettier": "^3.4.1",
8889
"rollup": "^4.16.2",
8990
"rollup-plugin-copy": "^3.5.0",
9091
"typescript": "^5.4.5",

src/index.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,23 @@ const plugin = {
3232
"no-invalid-at-rules": noInvalidAtRules,
3333
"no-invalid-properties": noInvalidProperties,
3434
},
35-
configs: {},
36-
};
37-
38-
Object.assign(plugin.configs, {
39-
recommended: {
40-
plugins: { css: plugin },
41-
rules: {
42-
"css/no-empty-blocks": "error",
43-
"css/no-duplicate-imports": "error",
44-
"css/no-invalid-at-rules": "error",
45-
"css/no-invalid-properties": "error",
35+
configs: {
36+
recommended: {
37+
plugins: {},
38+
rules: /** @type {const} */ ({
39+
"css/no-empty-blocks": "error",
40+
"css/no-duplicate-imports": "error",
41+
"css/no-invalid-at-rules": "error",
42+
"css/no-invalid-properties": "error",
43+
}),
4644
},
4745
},
48-
});
46+
};
47+
48+
// eslint-disable-next-line no-lone-blocks -- The block syntax { ... } ensures that TypeScript does not get confused about the type of `plugin`.
49+
{
50+
plugin.configs.recommended.plugins.css = plugin;
51+
}
4952

5053
export default plugin;
5154
export { CSSLanguage, CSSSourceCode };

src/rules/no-duplicate-imports.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
export default {
77
meta: {
8-
type: "problem",
8+
type: /** @type {const} */ ("problem"),
99

1010
docs: {
1111
description: "Disallow duplicate @import rules",

src/rules/no-empty-blocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
export default {
77
meta: {
8-
type: "problem",
8+
type: /** @type {const} */ ("problem"),
99

1010
docs: {
1111
description: "Disallow empty blocks",

0 commit comments

Comments
 (0)