diff --git a/.stylelintrc.js b/.stylelintrc.js new file mode 100644 index 0000000000..efbe9b7be1 --- /dev/null +++ b/.stylelintrc.js @@ -0,0 +1,13 @@ +/** + * 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. + */ + +module.exports = { + plugins: ['stylelint-copyright'], + rules: { + 'docusaurus/copyright-header': true, + }, +}; diff --git a/.stylelintrc.json b/.stylelintrc.json deleted file mode 100644 index 7fea1a6c60..0000000000 --- a/.stylelintrc.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "plugins": ["./packages/stylelint-copyright/index.js"], - "rules": { - "plugin/stylelint-copyright": true - } -} diff --git a/package.json b/package.json index d521faa73e..6b0516f8e4 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "react": "^16.8.4", "react-dom": "^16.8.4", "stylelint": "^13.2.0", + "stylelint-copyright": "1.0.0", "typescript": "^3.7.2" }, "lint-staged": { diff --git a/packages/docusaurus-init/templates/classic/src/css/custom.css b/packages/docusaurus-init/templates/classic/src/css/custom.css index ff93784ad3..74ba0f27f3 100644 --- a/packages/docusaurus-init/templates/classic/src/css/custom.css +++ b/packages/docusaurus-init/templates/classic/src/css/custom.css @@ -1,10 +1,4 @@ -/** - * 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. - */ - +/* stylelint-disable docusaurus/copyright-header */ /** * Any CSS included here will be global. The classic template * bundles Infima by default. Infima is a CSS framework designed to diff --git a/packages/docusaurus-init/templates/classic/src/pages/styles.module.css b/packages/docusaurus-init/templates/classic/src/pages/styles.module.css index 2099a9cd19..34f21992a2 100644 --- a/packages/docusaurus-init/templates/classic/src/pages/styles.module.css +++ b/packages/docusaurus-init/templates/classic/src/pages/styles.module.css @@ -1,10 +1,4 @@ -/** - * 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. - */ - +/* stylelint-disable docusaurus/copyright-header */ /** * CSS files with the .module.css suffix will be treated as CSS modules * and scoped locally. diff --git a/packages/docusaurus-init/templates/facebook/.stylelintrc.js b/packages/docusaurus-init/templates/facebook/.stylelintrc.js new file mode 100644 index 0000000000..efbe9b7be1 --- /dev/null +++ b/packages/docusaurus-init/templates/facebook/.stylelintrc.js @@ -0,0 +1,13 @@ +/** + * 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. + */ + +module.exports = { + plugins: ['stylelint-copyright'], + rules: { + 'docusaurus/copyright-header': true, + }, +}; diff --git a/packages/docusaurus-init/templates/facebook/.stylelintrc.json b/packages/docusaurus-init/templates/facebook/.stylelintrc.json deleted file mode 100644 index 8a55997c23..0000000000 --- a/packages/docusaurus-init/templates/facebook/.stylelintrc.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "plugins": ["../../..//stylelint-copyright/index.js"], - "rules": { - "plugin/stylelint-copyright": true - } -} diff --git a/packages/docusaurus-init/templates/facebook/package.json b/packages/docusaurus-init/templates/facebook/package.json index 681ea32f96..0d47c0c37d 100644 --- a/packages/docusaurus-init/templates/facebook/package.json +++ b/packages/docusaurus-init/templates/facebook/package.json @@ -17,8 +17,7 @@ "@docusaurus/preset-classic": "^2.0.0-alpha.43", "classnames": "^2.2.6", "react": "^16.8.4", - "react-dom": "^16.8.4", - "stylelint": "^13.2.0" + "react-dom": "^16.8.4" }, "devDependencies": { "babel-eslint": "^10.0.3", @@ -30,7 +29,8 @@ "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.16.0", "eslint-plugin-react-hooks": "^2.3.0", - "prettier": "^1.19.1" + "prettier": "^1.19.1", + "stylelint": "^13.2.0" }, "browserslist": { "production": [ diff --git a/packages/stylelint-copyright/README.md b/packages/stylelint-copyright/README.md index 32a76e8aec..93c8b4d2db 100644 --- a/packages/stylelint-copyright/README.md +++ b/packages/stylelint-copyright/README.md @@ -1,6 +1,6 @@ # stylelint-copyright -stylelint plugin to check css files for a copyright header +stylelint plugin to check CSS files for a copyright header. ```css /* @@ -11,12 +11,12 @@ stylelint plugin to check css files for a copyright header ## Usage -```js +```json // .stylelintrc { - "plugins": ["./packages/stylelint-copyright/index.js"], - "rules": { - "plugin/stylelint-copyright": true - } + "plugins": ["stylelint-copyright"], + "rules": { + "docusaurus/copyright-header": true + } } ``` diff --git a/packages/stylelint-copyright/_tests_/index.js b/packages/stylelint-copyright/_tests_/index.js deleted file mode 100644 index 82072b4f20..0000000000 --- a/packages/stylelint-copyright/_tests_/index.js +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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, - }, - ], -}); diff --git a/packages/stylelint-copyright/index.js b/packages/stylelint-copyright/index.js index 66639ba1ad..b8b4dacc7b 100644 --- a/packages/stylelint-copyright/index.js +++ b/packages/stylelint-copyright/index.js @@ -7,9 +7,9 @@ const stylelint = require('stylelint'); -const ruleName = 'plugin/stylelint-copyright'; +const ruleName = 'docusaurus/copyright-header'; const messages = stylelint.utils.ruleMessages(ruleName, { - rejected: 'Unexpected missing copyright in the first comment', + rejected: 'Missing copyright in the header comment', }); module.exports = stylelint.createPlugin(ruleName, actual => { @@ -23,7 +23,7 @@ module.exports = stylelint.createPlugin(ruleName, actual => { } root.walkComments(comment => { - // ignore root comments with copyright text + // Ignore root comments with copyright text. if ( comment === comment.parent.first && /[Cc]opyright/.test(comment.text) @@ -31,12 +31,12 @@ module.exports = stylelint.createPlugin(ruleName, actual => { return; } - // ignore non-root comments + // Ignore non-root comments. if (comment.type !== 'root' && comment !== comment.parent.first) { return; } - // ignore indented comments + // Ignore indented comments. if (comment.source.start.column > 1) { return; } diff --git a/packages/stylelint-copyright/package.json b/packages/stylelint-copyright/package.json index 0d5c1ae858..7c2c4f27fe 100644 --- a/packages/stylelint-copyright/package.json +++ b/packages/stylelint-copyright/package.json @@ -1,11 +1,14 @@ { - "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" - } + "name": "stylelint-copyright", + "version": "1.0.0", + "description": "stylelint plugin to check css files for a copyright header", + "main": "index.js", + "license": "MIT", + "scripts": { + "test": "node tests" + }, + "dependencies": { + "stylelint": "^13.2.0", + "stylelint-test-rule-tape": "^0.2.0" + } } diff --git a/packages/stylelint-copyright/tests/index.js b/packages/stylelint-copyright/tests/index.js new file mode 100644 index 0000000000..f0d77ef99c --- /dev/null +++ b/packages/stylelint-copyright/tests/index.js @@ -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. + */ + +const testRule = require('stylelint-test-rule-tape'); +const stylelintCopyright = require('..'); + +testRule(stylelintCopyright.rule, { + ruleName: stylelintCopyright.ruleName, + accept: [ + { + code: ` +/** + * Copyright + */ + + .foo {}`, + }, + { + code: ` + /** + * copyright + */ + + .foo {}`, + }, + ], + reject: [ + { + code: ` +/** + * Copyleft + */ + + .foo {}`, + message: `Missing copyright in the header comment (${stylelintCopyright.ruleName})`, + line: 2, + column: 1, + }, + { + code: ` +/** + * Copyleft + */ + +/** + * Copyright + */ + .foo {}`, + message: `Missing copyright in the header comment (${stylelintCopyright.ruleName})`, + line: 2, + column: 1, + }, + ], +});