diff --git a/.stylelintrc b/.stylelintrc index 3aa39bf0..8623eb88 100644 --- a/.stylelintrc +++ b/.stylelintrc @@ -16,5 +16,5 @@ } ] }, - "plugins": ["./build-tools/stylelint"] + "plugins": ["@cloudscape-design/build-tools/stylelint"] } diff --git a/build-tools/stylelint/index.js b/build-tools/stylelint/index.js deleted file mode 100644 index 2b1fc6b5..00000000 --- a/build-tools/stylelint/index.js +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -import licenseHeaders from "./license-headers.js"; - -export default [licenseHeaders]; diff --git a/build-tools/stylelint/license-headers.js b/build-tools/stylelint/license-headers.js deleted file mode 100644 index 84c47daa..00000000 --- a/build-tools/stylelint/license-headers.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -import stylelint from "stylelint"; - -const ruleName = "@cloudscape-design/license-headers"; -const messages = stylelint.utils.ruleMessages(ruleName, { - rejected: "Missing license header", -}); - -function licenseHeadersPlugin(enabled, { header }, context) { - if (!enabled) { - return; - } - - if (!header) { - throw new Error(`stylelint ${ruleName} rule requires a header option.`); - } - - const trimmedHeader = header.trim(); - - return (root, result) => { - let foundComment = false; - let firstComment = null; - - root.walkComments(function (comment) { - if (comment.parent.type === "root" && comment === comment.parent.first) { - if (!firstComment) { - firstComment = comment; - } - - if (comment.text.trim() === trimmedHeader) { - foundComment = true; - } - } - }); - - if (!foundComment) { - if (context.fix) { - const newComment = `/*${header}*/\n\n`; - root.prepend(newComment); - } else { - stylelint.utils.report({ - message: messages.rejected, - node: firstComment || root, - result, - ruleName, - }); - } - } - }; -} - -licenseHeadersPlugin.ruleName = ruleName; -licenseHeadersPlugin.messages = messages; - -export default stylelint.createPlugin(ruleName, licenseHeadersPlugin); diff --git a/build-tools/stylelint/package.json b/build-tools/stylelint/package.json deleted file mode 100644 index 3dbc1ca5..00000000 --- a/build-tools/stylelint/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/package-lock.json b/package-lock.json index b75b369f..eb0ff79f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ }, "devDependencies": { "@cloudscape-design/browser-test-tools": "^3.0.4", + "@cloudscape-design/build-tools": "^3.0.1", "@cloudscape-design/components": "^3", "@cloudscape-design/design-tokens": "^3", "@cloudscape-design/documenter": "^1.0.0", diff --git a/package.json b/package.json index ac253c05..35eb825e 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ }, "devDependencies": { "@cloudscape-design/browser-test-tools": "^3.0.4", + "@cloudscape-design/build-tools": "^3.0.1", "@cloudscape-design/components": "^3", "@cloudscape-design/design-tokens": "^3", "@cloudscape-design/documenter": "^1.0.0",