-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(stylelint-copyright): migrate to TS (#7441)
- Loading branch information
Showing
5 changed files
with
100 additions
and
70 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,58 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import stylelint from 'stylelint'; | ||
|
||
const ruleName = 'docusaurus/copyright-header'; | ||
const messages = stylelint.utils.ruleMessages(ruleName, { | ||
rejected: 'Missing copyright in the header comment', | ||
}); | ||
|
||
type SecondaryOption = {header?: string}; | ||
|
||
const plugin = stylelint.createPlugin( | ||
ruleName, | ||
(primaryOption: boolean, secondaryOption: SecondaryOption, context) => | ||
(root, result) => { | ||
stylelint.utils.validateOptions( | ||
result, | ||
ruleName, | ||
{ | ||
actual: primaryOption, | ||
possible: [true, false], | ||
}, | ||
{ | ||
actual: secondaryOption, | ||
possible: (v) => typeof (v as SecondaryOption)?.header === 'string', | ||
}, | ||
); | ||
|
||
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; | ||
} | ||
|
||
stylelint.utils.report({ | ||
message: messages.rejected, | ||
node: root, | ||
result, | ||
ruleName, | ||
}); | ||
}, | ||
); | ||
|
||
export = plugin; |
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,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"incremental": true, | ||
"tsBuildInfoFile": "./lib/.tsbuildinfo", | ||
"rootDir": "src", | ||
"outDir": "lib" | ||
} | ||
} |