|
1 | 1 | import css from "@eslint/css"; |
2 | 2 | import type { |
| 3 | + CSSLanguageOptions, |
3 | 4 | CSSRuleDefinition, |
4 | 5 | CSSRuleVisitor, |
5 | 6 | CSSSourceCode, |
| 7 | + DefaultSyntaxConfig, |
| 8 | + SyntaxExtensionCallback, |
6 | 9 | } from "@eslint/css"; |
7 | 10 | import type { Plugin, SourceLocation, SourceRange } from "@eslint/core"; |
8 | 11 | import type { ESLint } from "eslint"; |
@@ -76,6 +79,74 @@ css.rules[ruleName] satisfies CSSRuleDefinition; |
76 | 79 | // Check that `plugins` in the recommended config is defined: |
77 | 80 | css.configs.recommended.plugins satisfies object; |
78 | 81 |
|
| 82 | +const validLanguageOptions1: CSSLanguageOptions = {}; |
| 83 | +const validLanguageOptions2: CSSLanguageOptions = { |
| 84 | + tolerant: true, |
| 85 | +}; |
| 86 | +const validLanguageOptions3: CSSLanguageOptions = { |
| 87 | + tolerant: false, |
| 88 | +}; |
| 89 | +const validLanguageOptions4: CSSLanguageOptions = { |
| 90 | + customSyntax: { |
| 91 | + atrules: {}, |
| 92 | + properties: {}, |
| 93 | + types: {}, |
| 94 | + }, |
| 95 | +}; |
| 96 | +const validLanguageOptions5: CSSLanguageOptions = { |
| 97 | + customSyntax: defaultSyntax => { |
| 98 | + defaultSyntax satisfies DefaultSyntaxConfig; |
| 99 | + |
| 100 | + return { |
| 101 | + properties: { |
| 102 | + foo: "<ident>", |
| 103 | + }, |
| 104 | + }; |
| 105 | + }, |
| 106 | +}; |
| 107 | +const validLanguageOptions6: CSSLanguageOptions = { |
| 108 | + tolerant: true, |
| 109 | + unknownOption: "unknown", |
| 110 | +}; |
| 111 | + |
| 112 | +const invalidLanguageOptions1: CSSLanguageOptions = { |
| 113 | + // @ts-expect-error -- Invalid value for `tolerant` |
| 114 | + tolerant: "true", |
| 115 | +}; |
| 116 | +const invalidLanguageOptions2: CSSLanguageOptions = { |
| 117 | + // @ts-expect-error -- Invalid value for `customSyntax` |
| 118 | + customSyntax: "invalid", |
| 119 | +}; |
| 120 | + |
| 121 | +const defaultSyntaxConfig: DefaultSyntaxConfig = { |
| 122 | + atrules: {}, |
| 123 | + types: {}, |
| 124 | + properties: {}, |
| 125 | +}; |
| 126 | + |
| 127 | +// @ts-expect-error -- Default syntax configuration requires `properties`. |
| 128 | +const invalidDefaultSyntaxConfig: DefaultSyntaxConfig = { |
| 129 | + atrules: {}, |
| 130 | + types: {}, |
| 131 | +}; |
| 132 | + |
| 133 | +const syntaxExtensionCallback: SyntaxExtensionCallback = defaultSyntax => { |
| 134 | + defaultSyntax satisfies DefaultSyntaxConfig; |
| 135 | + |
| 136 | + return { |
| 137 | + properties: { |
| 138 | + foo: "<ident>", |
| 139 | + }, |
| 140 | + }; |
| 141 | +}; |
| 142 | + |
| 143 | +const invalidSyntaxExtensionCallback: SyntaxExtensionCallback = () => ({ |
| 144 | + properties: { |
| 145 | + // @ts-expect-error -- CSS property syntax definitions must be strings. |
| 146 | + foo: 1, |
| 147 | + }, |
| 148 | +}); |
| 149 | + |
79 | 150 | { |
80 | 151 | type RecommendedRuleName = keyof typeof css.configs.recommended.rules; |
81 | 152 | type RuleName = `css/${keyof typeof css.rules}`; |
|
0 commit comments