-
-
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.
* Add stylelint * Add custom stylelint plugin for copyright * Add stylelint to FB template
- Loading branch information
Showing
11 changed files
with
1,462 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": ["./packages/stylelint-copyright/index.js"], | ||
"rules": { | ||
"plugin/stylelint-copyright": true | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
packages/docusaurus-init/templates/classic/src/css/custom.css
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
7 changes: 7 additions & 0 deletions
7
packages/docusaurus-init/templates/classic/src/pages/styles.module.css
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
6 changes: 6 additions & 0 deletions
6
packages/docusaurus-init/templates/facebook/.stylelintrc.json
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,6 @@ | ||
{ | ||
"plugins": ["../../..//stylelint-copyright/index.js"], | ||
"rules": { | ||
"plugin/stylelint-copyright": true | ||
} | ||
} |
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,22 @@ | ||
# stylelint-copyright | ||
|
||
stylelint plugin to check css files for a copyright header | ||
|
||
```css | ||
/* | ||
* Copyright ... | ||
* ... | ||
*/ | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
// .stylelintrc | ||
{ | ||
"plugins": ["./packages/stylelint-copyright/index.js"], | ||
"rules": { | ||
"plugin/stylelint-copyright": true | ||
} | ||
} | ||
``` |
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,32 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
const testRule = require('stylelint-test-rule-tape'); | ||
const selectorCopyright = require('..'); | ||
|
||
testRule(selectorCopyright.rule, { | ||
ruleName: selectorCopyright.ruleName, | ||
config: [true], | ||
accept: [ | ||
{ | ||
code: '/**\n* Copyright', | ||
description: 'Copyright in the first comment', | ||
}, | ||
{ | ||
code: '/**\n* copyright', | ||
description: 'Copyright in the first comment', | ||
}, | ||
], | ||
reject: [ | ||
{ | ||
code: '/**\n* Hello', | ||
message: 'Missing copyright in the first comment', | ||
line: 2, | ||
column: 3, | ||
}, | ||
], | ||
}); |
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,55 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
const stylelint = require('stylelint'); | ||
|
||
const ruleName = 'plugin/stylelint-copyright'; | ||
const messages = stylelint.utils.ruleMessages(ruleName, { | ||
rejected: 'Unexpected missing copyright in the first comment', | ||
}); | ||
|
||
module.exports = stylelint.createPlugin(ruleName, actual => { | ||
return (root, result) => { | ||
const validOptions = stylelint.utils.validateOptions(result, ruleName, { | ||
actual, | ||
}); | ||
|
||
if (!validOptions) { | ||
return; | ||
} | ||
|
||
root.walkComments(comment => { | ||
// ignore root comments with copyright text | ||
if ( | ||
comment === comment.parent.first && | ||
/[Cc]opyright/.test(comment.text) | ||
) { | ||
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, | ||
}); | ||
}); | ||
}; | ||
}); | ||
|
||
module.exports.ruleName = ruleName; | ||
module.exports.messages = messages; |
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,11 @@ | ||
{ | ||
"name": "stylelint-copyright", | ||
"version": "1.0.0", | ||
"description": "stylelint plugin to check css files for a copyright header", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"stylelint": "^13.2.0", | ||
"stylelint-test-rule-tape": "^0.2.0" | ||
} | ||
} |
Oops, something went wrong.