1
- import type { Declaration , Root , Result } from 'postcss' ;
2
- import stylelint , { LinterOptions , Plugin } from 'stylelint' ;
1
+ import type { Declaration , Root , Result , AtRule } from 'postcss' ;
2
+ import stylelint from 'stylelint' ;
3
3
import shortCSS from 'shortcss' ;
4
4
import list from 'shortcss/lib/list' ;
5
5
import cssValues from 'css-values' ;
@@ -84,6 +84,9 @@ const mapIgnoreValue = (ignoreValue: TOptionPrimitive) =>
84
84
* @param {object } result - PostCSS lazy result.
85
85
*/
86
86
type PostCSSPlugin = ( root : Root , result : Result ) => void | PromiseLike < void > ;
87
+ interface StylelintContext {
88
+ fix ?: boolean ;
89
+ }
87
90
88
91
/**
89
92
* Stylelint declaration strict value rule function.
@@ -99,14 +102,14 @@ interface StylelintRuleFunction {
99
102
(
100
103
primaryOption : string | string [ ] ,
101
104
secondaryOptions ?: ISecondaryOptions ,
102
- context ?: LinterOptions
105
+ context ?: StylelintContext
103
106
) : PostCSSPlugin ;
104
107
primaryOptionArray : boolean ;
105
108
}
106
109
const ruleFunction : StylelintRuleFunction = (
107
110
properties : string | string [ ] ,
108
111
options : ISecondaryOptions ,
109
- context : LinterOptions
112
+ context : StylelintContext = { }
110
113
) => ( root : Root , result : Result ) => {
111
114
// validate stylelint plugin options
112
115
const hasValidOptions = utils . validateOptions (
@@ -161,7 +164,7 @@ const ruleFunction: StylelintRuleFunction = (
161
164
162
165
if ( ignoreVariables ) {
163
166
const cssLoaderValuesNames : string [ ] = [ ] ;
164
- root . walkAtRules ( 'value' , ( rule ) => {
167
+ root . walkAtRules ( 'value' , ( rule : AtRule ) => {
165
168
const { params } = rule ;
166
169
const name = params . split ( ':' ) [ 0 ] . trim ( ) ;
167
170
@@ -343,7 +346,7 @@ const ruleFunction: StylelintRuleFunction = (
343
346
const types = getTypes ( config , property ) ;
344
347
345
348
// support auto fixing
346
- if ( context ? .fix && ! disableFix ) {
349
+ if ( context . fix && ! disableFix ) {
347
350
const fixedValue = autoFixFuncNormalized ! (
348
351
node ,
349
352
{
@@ -365,7 +368,8 @@ const ruleFunction: StylelintRuleFunction = (
365
368
}
366
369
} else {
367
370
const { raws } = node ;
368
- const { start } = node . source ! ;
371
+ // eslint-disable-next-line prefer-destructuring
372
+ const start = node . source ! . start ;
369
373
370
374
utils . report ( {
371
375
ruleName,
@@ -389,7 +393,7 @@ ruleFunction.primaryOptionArray = true;
389
393
390
394
const declarationStrictValuePlugin = stylelint . createPlugin (
391
395
ruleName ,
392
- ( ruleFunction as unknown ) as Plugin
396
+ ruleFunction
393
397
) ;
394
398
395
399
export default declarationStrictValuePlugin ;
0 commit comments