mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-05 12:22:45 +02:00
feat(stylelint-copyright): autofix, stricter config (#6374)
* feat(stylelint-copyright): autofix, stricter config * revert TS * oops
This commit is contained in:
parent
284c6166e7
commit
14bec7cf11
12 changed files with 202 additions and 176 deletions
|
@ -12,45 +12,50 @@ const messages = stylelint.utils.ruleMessages(ruleName, {
|
|||
rejected: 'Missing copyright in the header comment',
|
||||
});
|
||||
|
||||
module.exports = stylelint.createPlugin(
|
||||
const plugin = stylelint.createPlugin(
|
||||
ruleName,
|
||||
(actual) => (root, result) => {
|
||||
const validOptions = stylelint.utils.validateOptions(result, ruleName, {
|
||||
actual,
|
||||
});
|
||||
(primaryOption, secondaryOption, context) => (root, result) => {
|
||||
const validOptions = stylelint.utils.validateOptions(
|
||||
result,
|
||||
ruleName,
|
||||
{
|
||||
actual: primaryOption,
|
||||
possible: [true, false],
|
||||
},
|
||||
{
|
||||
actual: secondaryOption,
|
||||
possible: (v) => typeof v.header === 'string',
|
||||
},
|
||||
);
|
||||
|
||||
if (!validOptions) {
|
||||
return;
|
||||
}
|
||||
|
||||
root.walkComments((comment) => {
|
||||
// Ignore root comments with copyright text.
|
||||
if (
|
||||
comment === comment.parent.first &&
|
||||
/[Cc]opyright/.test(comment.text)
|
||||
) {
|
||||
if (
|
||||
root.first &&
|
||||
root.first.type === 'comment' &&
|
||||
root.first.source.start.column === 1
|
||||
) {
|
||||
const {text} = root.first;
|
||||
if (text === secondaryOption.header) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (context.fix) {
|
||||
root.first?.before(`/*${secondaryOption.header}\n */`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore non-root comments.
|
||||
if (comment.type !== 'root' && comment !== comment.parent.first) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore indented comments.
|
||||
if (comment.source.start.column > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
stylelint.utils.report({
|
||||
message: messages.rejected,
|
||||
node: comment,
|
||||
result,
|
||||
ruleName,
|
||||
});
|
||||
stylelint.utils.report({
|
||||
message: messages.rejected,
|
||||
node: root,
|
||||
result,
|
||||
ruleName,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
module.exports = plugin;
|
||||
module.exports.ruleName = ruleName;
|
||||
module.exports.messages = messages;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue