From f4d8246d3ed68119eac26395c07136ba7e7bbd84 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 11 Oct 2024 14:45:51 +0200 Subject: [PATCH] chore: Use @cloudscape-design/build-tools stylelint rules (#49) --- .stylelintrc | 2 +- build-tools/stylelint/index.js | 5 --- build-tools/stylelint/license-headers.js | 56 ------------------------ build-tools/stylelint/package.json | 3 -- package-lock.json | 1 + package.json | 1 + 6 files changed, 3 insertions(+), 65 deletions(-) delete mode 100644 build-tools/stylelint/index.js delete mode 100644 build-tools/stylelint/license-headers.js delete mode 100644 build-tools/stylelint/package.json diff --git a/.stylelintrc b/.stylelintrc index b22b27f..1a64539 100644 --- a/.stylelintrc +++ b/.stylelintrc @@ -14,5 +14,5 @@ } ] }, - "plugins": ["stylelint-use-logical", "stylelint-order", "./build-tools/stylelint"] + "plugins": ["stylelint-use-logical", "stylelint-order", "@cloudscape-design/build-tools/stylelint"] } diff --git a/build-tools/stylelint/index.js b/build-tools/stylelint/index.js deleted file mode 100644 index 2b1fc6b..0000000 --- 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 84c47da..0000000 --- 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 3dbc1ca..0000000 --- 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 b766315..6c00957 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,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 2ab0fad..2afa23c 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,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",