1- import { createPlugin , Plugin , utils } from 'stylelint' ;
1+ import { createPlugin , utils } from 'stylelint' ;
22import { basename , join } from 'path' ;
3- import { Result , Root } from 'postcss' ;
43
54const ruleName = 'material/no-unused-import' ;
65const messages = utils . ruleMessages ( ruleName , {
@@ -11,8 +10,8 @@ const messages = utils.ruleMessages(ruleName, {
1110} ) ;
1211
1312/** Stylelint plugin that flags unused `@use` statements. */
14- const factory = ( isEnabled : boolean , _options : never , context : { fix : boolean } ) => {
15- return ( root : Root , result : Result ) => {
13+ const plugin = createPlugin ( ruleName , ( isEnabled : boolean , _options , context ) => {
14+ return ( root , result ) => {
1615 if ( ! isEnabled ) {
1716 return ;
1817 }
@@ -26,29 +25,27 @@ const factory = (isEnabled: boolean, _options: never, context: {fix: boolean}) =
2625 // Flag namespaces we didn't manage to parse so that we can fix the parsing logic.
2726 if ( ! namespace ) {
2827 utils . report ( {
29- // We need these `as any` casts, because Stylelint uses an older version
30- // of the postcss typings that don't match up with our anymore.
31- result : result as any ,
28+ result,
3229 ruleName,
3330 message : messages . invalid ( rule . params ) ,
34- node : rule as any ,
31+ node : rule ,
3532 } ) ;
3633 } else if ( ! fileContent . includes ( namespace + '.' ) ) {
3734 if ( context . fix ) {
3835 rule . remove ( ) ;
3936 } else {
4037 utils . report ( {
41- result : result as any ,
38+ result,
4239 ruleName,
4340 message : messages . expected ( namespace ) ,
44- node : rule as any ,
41+ node : rule ,
4542 } ) ;
4643 }
4744 }
4845 }
4946 } ) ;
5047 } ;
51- } ;
48+ } ) ;
5249
5350/** Extracts the namespace of an `@use` rule from its parameters. */
5451function extractNamespaceFromUseStatement ( params : string ) : string | null {
@@ -88,9 +85,4 @@ function extractNamespaceFromUseStatement(params: string): string | null {
8885 return null ;
8986}
9087
91- // Note: We need to cast the value explicitly to `Plugin` because the stylelint types
92- // do not type the context parameter. https://stylelint.io/developer-guide/rules#add-autofix
93- const plugin = createPlugin ( ruleName , factory as unknown as Plugin ) ;
94- plugin . ruleName = ruleName ;
95- plugin . messages = messages ;
96- module . exports = plugin ;
88+ export default plugin ;
0 commit comments