Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/vscode-bicep-ui/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
legacy-peer-deps=true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is risky as it ignores peer dependency conflicts and the consumer of the package can hit install errors or runtime bugs. We may need to remove it.

60 changes: 51 additions & 9 deletions src/vscode-bicep-ui/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,58 @@
// For more info, see https://github.com/storybookjs/eslint-plugin-storybook#configuration-flat-config-format
import eslint from "@eslint/js";
import notice from "eslint-plugin-notice";
import reactPlugin from "eslint-plugin-react";
import reactHooksPlugin from "eslint-plugin-react-hooks";
import reactRefreshPlugin from "eslint-plugin-react-refresh";
import tseslint from "typescript-eslint";

const copyrightNoticeTemplate =
"// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n";

const copyrightNoticeRule = {
meta: {
type: "suggestion",
fixable: "code",
docs: {
description: "Enforce Microsoft copyright and license notice at the top of TypeScript files.",
},
messages: {
missing: "Missing or incorrect copyright notice header.",
},
},
create(context) {
return {
Program(node) {
const sourceCode = context.sourceCode;
const text = sourceCode.getText();
if (!text.startsWith(copyrightNoticeTemplate)) {
context.report({
node,
messageId: "missing",
fix(fixer) {
// Determine how many characters of an existing (incorrect) header to replace.
// Replace any leading comment lines (starting with "//") so we don't produce duplicates.
let replaceEnd = 0;
if (text.startsWith("//")) {
const lines = text.split("\n");
let i = 0;
while (i < lines.length && lines[i].startsWith("//")) {
i++;
}
// Also consume one blank line after the header comments if present
if (i < lines.length && lines[i] === "") {
i++;
}
replaceEnd = lines.slice(0, i).join("\n").length + (i < lines.length ? 1 : 0);
}
return fixer.replaceTextRange([0, replaceEnd], copyrightNoticeTemplate);
},
});
}
},
};
},
};

export default tseslint.config(
{
ignores: ["**/*.{js,cjs,mjs}", "**/.turbo/", "**/dist/"],
Expand All @@ -19,23 +66,18 @@ export default tseslint.config(
reactPlugin.configs.flat["jsx-runtime"],
],
plugins: {
notice,
"copyright-notice": { rules: { notice: copyrightNoticeRule } },
"react-refresh": reactRefreshPlugin,
"react-hooks": reactHooksPlugin,
},
settings: {
react: {
version: "detect",
version: "18",
},
},
rules: {
...reactHooksPlugin.configs.recommended.rules,
"notice/notice": [
"error",
{
template: `// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n`,
},
],
"copyright-notice/notice": "error",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
Expand Down
Loading