-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add cloudscape stylelint (#38)
- Upgrade necessary packages - Add custom cloudscape stylelint - Running linting for project
- Loading branch information
1 parent
50fc488
commit 91f1937
Showing
19 changed files
with
438 additions
and
553 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
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,5 @@ | ||
// 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]; |
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,56 @@ | ||
// 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); |
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,3 @@ | ||
{ | ||
"type": "module" | ||
} |
Oops, something went wrong.