-
-
Notifications
You must be signed in to change notification settings - Fork 929
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate all rules to ESM again (#7262)
1. Run `node scripts/rewrite-rules-to-esm.mjs` 2. Manually fix lint and test failures Note that `scripts/rewrite-rules-to-esm.mjs` is removed.
- Loading branch information
1 parent
6d040b2
commit 0f28bc6
Showing
379 changed files
with
15,548 additions
and
945 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import valueParser from 'postcss-value-parser'; | ||
|
||
import { isRegExp, isString } from '../../utils/validateTypes.mjs'; | ||
import getDeclarationValue from '../../utils/getDeclarationValue.mjs'; | ||
import isStandardSyntaxValue from '../../utils/isStandardSyntaxValue.mjs'; | ||
import optionsMatches from '../../utils/optionsMatches.mjs'; | ||
import report from '../../utils/report.mjs'; | ||
import ruleMessages from '../../utils/ruleMessages.mjs'; | ||
import validateOptions from '../../utils/validateOptions.mjs'; | ||
|
||
const ruleName = 'annotation-no-unknown'; | ||
|
||
const messages = ruleMessages(ruleName, { | ||
rejected: (annotation) => `Unexpected unknown annotation "${annotation}"`, | ||
}); | ||
|
||
const meta = { | ||
url: 'https://stylelint.io/user-guide/rules/annotation-no-unknown', | ||
}; | ||
|
||
/** @type {import('stylelint').Rule} */ | ||
const rule = (primary, secondaryOptions) => { | ||
return (root, result) => { | ||
const validOptions = validateOptions( | ||
result, | ||
ruleName, | ||
{ actual: primary }, | ||
{ | ||
actual: secondaryOptions, | ||
possible: { | ||
ignoreAnnotations: [isString, isRegExp], | ||
}, | ||
optional: true, | ||
}, | ||
); | ||
|
||
if (!validOptions) { | ||
return; | ||
} | ||
|
||
root.walkDecls(checkStatement); | ||
|
||
/** | ||
* @param {import('postcss').Declaration} decl | ||
*/ | ||
function checkStatement(decl) { | ||
if (!isStandardSyntaxValue(decl.value)) return; | ||
|
||
if (decl.important) return; | ||
|
||
if (!decl.value.includes('!')) return; | ||
|
||
const parsedValue = valueParser(getDeclarationValue(decl)); | ||
|
||
parsedValue.walk((node) => { | ||
if (!isAnnotation(node)) return; | ||
|
||
const value = node.value; | ||
const tokenValue = value.slice(1); | ||
|
||
if (optionsMatches(secondaryOptions, 'ignoreAnnotations', tokenValue)) { | ||
return; | ||
} | ||
|
||
report({ | ||
message: messages.rejected, | ||
messageArgs: [value], | ||
node: decl, | ||
result, | ||
ruleName, | ||
word: value, | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* @param {valueParser.Node} node | ||
*/ | ||
function isAnnotation(node) { | ||
return node.type === 'word' && node.value.startsWith('!'); | ||
} | ||
}; | ||
}; | ||
|
||
rule.ruleName = ruleName; | ||
rule.messages = messages; | ||
rule.meta = meta; | ||
export default rule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import isStandardSyntaxAtRule from '../../utils/isStandardSyntaxAtRule.mjs'; | ||
import { isString } from '../../utils/validateTypes.mjs'; | ||
import report from '../../utils/report.mjs'; | ||
import ruleMessages from '../../utils/ruleMessages.mjs'; | ||
import validateOptions from '../../utils/validateOptions.mjs'; | ||
import vendor from '../../utils/vendor.mjs'; | ||
|
||
const ruleName = 'at-rule-allowed-list'; | ||
|
||
const messages = ruleMessages(ruleName, { | ||
rejected: (name) => `Unexpected at-rule "${name}"`, | ||
}); | ||
|
||
const meta = { | ||
url: 'https://stylelint.io/user-guide/rules/at-rule-allowed-list', | ||
}; | ||
|
||
/** @type {import('stylelint').Rule<string | string[]>} */ | ||
const rule = (primary) => { | ||
return (root, result) => { | ||
const validOptions = validateOptions(result, ruleName, { | ||
actual: primary, | ||
possible: [isString], | ||
}); | ||
|
||
if (!validOptions) { | ||
return; | ||
} | ||
|
||
const primaryValues = [primary].flat(); | ||
|
||
root.walkAtRules((atRule) => { | ||
const name = atRule.name; | ||
|
||
if (!isStandardSyntaxAtRule(atRule)) { | ||
return; | ||
} | ||
|
||
if (primaryValues.includes(vendor.unprefixed(name).toLowerCase())) { | ||
return; | ||
} | ||
|
||
report({ | ||
message: messages.rejected, | ||
messageArgs: [name], | ||
node: atRule, | ||
result, | ||
ruleName, | ||
word: `@${name}`, | ||
}); | ||
}); | ||
}; | ||
}; | ||
|
||
rule.primaryOptionArray = true; | ||
|
||
rule.ruleName = ruleName; | ||
rule.messages = messages; | ||
rule.meta = meta; | ||
export default rule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import isStandardSyntaxAtRule from '../../utils/isStandardSyntaxAtRule.mjs'; | ||
import { isString } from '../../utils/validateTypes.mjs'; | ||
import report from '../../utils/report.mjs'; | ||
import ruleMessages from '../../utils/ruleMessages.mjs'; | ||
import validateOptions from '../../utils/validateOptions.mjs'; | ||
import vendor from '../../utils/vendor.mjs'; | ||
|
||
const ruleName = 'at-rule-disallowed-list'; | ||
|
||
const messages = ruleMessages(ruleName, { | ||
rejected: (name) => `Unexpected at-rule "${name}"`, | ||
}); | ||
|
||
const meta = { | ||
url: 'https://stylelint.io/user-guide/rules/at-rule-disallowed-list', | ||
}; | ||
|
||
/** @type {import('stylelint').Rule<string | string[]>} */ | ||
const rule = (primary) => { | ||
return (root, result) => { | ||
const validOptions = validateOptions(result, ruleName, { | ||
actual: primary, | ||
possible: [isString], | ||
}); | ||
|
||
if (!validOptions) { | ||
return; | ||
} | ||
|
||
const primaryValues = [primary].flat(); | ||
|
||
root.walkAtRules((atRule) => { | ||
const name = atRule.name; | ||
|
||
if (!isStandardSyntaxAtRule(atRule)) { | ||
return; | ||
} | ||
|
||
if (!primaryValues.includes(vendor.unprefixed(name).toLowerCase())) { | ||
return; | ||
} | ||
|
||
report({ | ||
message: messages.rejected, | ||
messageArgs: [name], | ||
node: atRule, | ||
result, | ||
ruleName, | ||
word: `@${atRule.name}`, | ||
}); | ||
}); | ||
}; | ||
}; | ||
|
||
rule.primaryOptionArray = true; | ||
|
||
rule.ruleName = ruleName; | ||
rule.messages = messages; | ||
rule.meta = meta; | ||
export default rule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.