mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +02:00
chore(v2): add stylelint (#2361)
* Add stylelint * Add custom stylelint plugin for copyright * Add stylelint to FB template
This commit is contained in:
parent
4aee06e74f
commit
ae78c1e6dd
11 changed files with 1462 additions and 36 deletions
6
.stylelintrc.json
Normal file
6
.stylelintrc.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"plugins": ["./packages/stylelint-copyright/index.js"],
|
||||||
|
"rules": {
|
||||||
|
"plugin/stylelint-copyright": true
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,7 +18,7 @@
|
||||||
"prettier": "prettier --config .prettierrc --write \"**/*.{js,ts}\"",
|
"prettier": "prettier --config .prettierrc --write \"**/*.{js,ts}\"",
|
||||||
"prettier:diff": "prettier --config .prettierrc --list-different \"**/*.{js,ts}\"",
|
"prettier:diff": "prettier --config .prettierrc --list-different \"**/*.{js,ts}\"",
|
||||||
"prettier-docs": "prettier --config .prettierrc --write \"**/*.md\"",
|
"prettier-docs": "prettier --config .prettierrc --write \"**/*.md\"",
|
||||||
"lint": "eslint --cache \"**/*.js\"",
|
"lint": "eslint --cache \"**/*.js\" && stylelint \"**/*.css\"",
|
||||||
"lerna": "lerna",
|
"lerna": "lerna",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"tsc": "lerna run tsc --no-private"
|
"tsc": "lerna run tsc --no-private"
|
||||||
|
@ -62,6 +62,7 @@
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^1.19.1",
|
||||||
"react": "^16.8.4",
|
"react": "^16.8.4",
|
||||||
"react-dom": "^16.8.4",
|
"react-dom": "^16.8.4",
|
||||||
|
"stylelint": "^13.2.0",
|
||||||
"typescript": "^3.7.2"
|
"typescript": "^3.7.2"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Any CSS included here will be global. The classic template
|
* Any CSS included here will be global. The classic template
|
||||||
* bundles Infima by default. Infima is a CSS framework designed to
|
* bundles Infima by default. Infima is a CSS framework designed to
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CSS files with the .module.css suffix will be treated as CSS modules
|
* CSS files with the .module.css suffix will be treated as CSS modules
|
||||||
* and scoped locally.
|
* and scoped locally.
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"plugins": ["../../..//stylelint-copyright/index.js"],
|
||||||
|
"rules": {
|
||||||
|
"plugin/stylelint-copyright": true
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,7 +8,7 @@
|
||||||
"swizzle": "docusaurus swizzle",
|
"swizzle": "docusaurus swizzle",
|
||||||
"deploy": "docusaurus deploy",
|
"deploy": "docusaurus deploy",
|
||||||
"ci": "yarn lint && yarn prettier:diff",
|
"ci": "yarn lint && yarn prettier:diff",
|
||||||
"lint": "eslint --cache \"**/*.js\"",
|
"lint": "eslint --cache \"**/*.js\" && stylelint \"**/*.css\"",
|
||||||
"prettier": "prettier --config .prettierrc --write \"**/*.{js,md}\"",
|
"prettier": "prettier --config .prettierrc --write \"**/*.{js,md}\"",
|
||||||
"prettier:diff": "prettier --config .prettierrc --list-different \"**/*.{js,md}\""
|
"prettier:diff": "prettier --config .prettierrc --list-different \"**/*.{js,md}\""
|
||||||
},
|
},
|
||||||
|
@ -17,7 +17,8 @@
|
||||||
"@docusaurus/preset-classic": "^2.0.0-alpha.43",
|
"@docusaurus/preset-classic": "^2.0.0-alpha.43",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "^2.2.6",
|
||||||
"react": "^16.8.4",
|
"react": "^16.8.4",
|
||||||
"react-dom": "^16.8.4"
|
"react-dom": "^16.8.4",
|
||||||
|
"stylelint": "^13.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-eslint": "^10.0.3",
|
"babel-eslint": "^10.0.3",
|
||||||
|
|
22
packages/stylelint-copyright/README.md
Normal file
22
packages/stylelint-copyright/README.md
Normal file
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
32
packages/stylelint-copyright/_tests_/index.js
Normal file
32
packages/stylelint-copyright/_tests_/index.js
Normal file
|
@ -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,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
55
packages/stylelint-copyright/index.js
Normal file
55
packages/stylelint-copyright/index.js
Normal file
|
@ -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;
|
11
packages/stylelint-copyright/package.json
Normal file
11
packages/stylelint-copyright/package.json
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue