Skip to content

Commit 6a0b08d

Browse files
danielrentzjeddy3
andauthored
Fix Could not find a declaration file for module 'css-tree' type error (#8452)
Co-authored-by: Richard Hallows <jeddy3@users.noreply.github.com>
1 parent 42108ad commit 6a0b08d

5 files changed

Lines changed: 19 additions & 7 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"stylelint": minor
3+
---
4+
5+
Fixed: `Could not find a declaration file for module 'css-tree'` type error

docs/developer-guide/rules.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ function rule(primary, secondary) {
307307
- `configurationComment`(string): String that prefixes configuration comments like `/* stylelint-disable */`.
308308
- `fix`(boolean): If `true`, your rule can apply autofixes.
309309
- `newline`(string): Line-ending used in current linted file.
310-
- `lexer`(object): The [CSSTree](https://github.com/csstree/csstree) lexer, which helps in parsing and validating CSS syntax dynamically. The lexer is initialized once per lint session and reused across rules.
311310

312311
> [!WARNING]
313312
> The convention of restricting the appliance of fixes based on the `context.fix` property is deprecated in favour of recommending the `fix` callback which properly handles [configuration comments](../user-guide/ignore-code.md#parts-of-a-file).

lib/utils/getLexer.cjs

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/utils/getLexer.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
/**
2+
* @typedef {import('css-tree').Lexer} Lexer
3+
*/
4+
15
/**
26
* @param {import('stylelint').RuleContext} context
3-
* @returns {import('css-tree').Lexer}
7+
* @returns {Lexer}
48
*/
59
export default function getLexer(context) {
610
if (!context?.lexer) {
711
throw new Error('Expected a "lexer" object');
812
}
913

10-
return context.lexer;
14+
return /** @type Lexer */ (context.lexer);
1115
}

types/stylelint/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type * as PostCSS from 'postcss';
22
import type { GlobbyOptions } from 'globby';
33
import type { cosmiconfig, TransformSync as CosmiconfigTransformSync } from 'cosmiconfig';
4-
import type { Lexer } from 'css-tree';
54

65
type ConfigExtends = string | string[];
76

@@ -371,7 +370,8 @@ declare namespace stylelint {
371370
configurationComment?: string | undefined;
372371
fix?: boolean | undefined;
373372
newline?: string | undefined;
374-
lexer?: Lexer | undefined;
373+
/** @internal */
374+
lexer?: unknown | undefined;
375375
};
376376

377377
/** @internal */

0 commit comments

Comments
 (0)