Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users/v rakeshsh/eslint migration #7527

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const baseModule = require('./eslintrc.base');
module.exports = {
import baseModule from './eslint.config.mjs';

export default {
...baseModule,
root: true,
ignorePatterns: [
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify-unchanged-strict-null-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
//
// This serves as a reminder for humans to update strict null checks when they add files.

const child_process = require('child_process');
const path = require('path');
const process = require('process');
const child_process = require('child_process');

const lockfilePath = path.join(__dirname, '..', '..', 'tsconfig.strictNullChecks.json');

Expand Down
144 changes: 144 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
import { fixupPluginRules } from "@eslint/compat";
import { FlatCompat } from "@eslint/eslintrc";
import js from "@eslint/js";
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import _import from "eslint-plugin-import";
import react from "eslint-plugin-react";
import security from "eslint-plugin-security";
import globals from "globals";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [{
ignores: [
"**/node_modules/",
"**/*bundle.js",
"**/dist/",
"**/drop/",
"**/extension/",
"**/packages/",
"**/test-results/",
"src/DetailsView/components/generated-validate-assessment-json.js",
"**/replace-plugin.js",
],
}, ...compat.extends(
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",

), {
plugins: {
react,
"@typescript-eslint": typescriptEslint,
security,
import: fixupPluginRules(_import),
},

languageOptions: {
globals: {
...globals.browser,
...globals.node,
},

parser: tsParser,
ecmaVersion: 8,
sourceType: "module",

parserOptions: {
project: [`{./tsconfig.json}`],

ecmaFeatures: {
jsx: true,
},
},
},

settings: {
react: {
version: "detect",
},
},

rules: {
eqeqeq: ["error", "always", {
null: "ignore",
}],

"import/order": ["error", {
alphabetize: {
order: "asc",
caseInsensitive: true,
},
}],

"no-restricted-imports": ["error", {
paths: [{
name: "typemoq",
importNames: ["GlobalMock", "GlobalScope"],
message: "typemoq Global mocks are incompatible with recent versions of @swc/core, see swc-project/swc#5151",
}],
}],

"no-throw-literal": "error",
"react/no-access-state-in-setstate": "error",
"react/no-unused-state": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/require-await": "off",
"@typescript-eslint/no-implied-eval": "off",
"@typescript-eslint/prefer-regexp-exec": "off",
"@typescript-eslint/await-thenable": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-for-in-array": "off",
"react/prop-types": "off",
"react/display-name": "off",
"react/no-unescaped-entities": "off",
"react/no-direct-mutation-state": "off",
"security/detect-object-injection": "off",
"no-prototype-builtins": "off",
},
}, {
files: [
"src/tests/**/*",
"tools/**/*",
"pipeline/**/*",
"deploy/**/*",
"**/Gruntfile.js",
],

rules: {
"security/detect-non-literal-regexp": "off",
"security/detect-non-literal-fs-filename": "off",
"security/detect-unsafe-regex": "off",
"security/detect-child-process": "off",
"security/detect-eval-with-expression": "off",
},
}];
4 changes: 2 additions & 2 deletions eslintrc.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:security/recommended',
// 'plugin:security/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
Expand Down Expand Up @@ -61,7 +61,7 @@ module.exports = {
'react/no-unused-state': 'error',

// Disabled due to high existing-positive count during initial tslint -> eslint migration
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/ban-types': 'off',
Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"format:fix": "prettier --config prettier.config.js --write \"**/*\"",
"lint:check": "eslint \"**/*.{js,ts,tsx}\"",
"lint:check:all": "yarn lint:check && yarn lint:scss && yarn packages run lint:check",
"lint:fix": "eslint \"**/*.{js,ts,tsx}\" --quiet --fix",
"lint:fix": "eslint '**/*.{js,ts,tsx}' --quiet --fix",
"lint:scss": "stylelint \"**/*.scss\"",
"lint:scss:fix": "stylelint \"**/*.scss\" --fix",
"null:autoadd": "node ./tools/strict-null-checks/auto-add.js",
Expand Down Expand Up @@ -96,18 +96,18 @@
"@types/uuid": "^9.0.7",
"@types/webextension-polyfill": "^0.10.7",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^6.18.1",
"@typescript-eslint/parser": "^8.19.1",
"case-sensitive-paths-webpack-plugin": "^2.4.0",
"codecov": "^3.8.3",
"commander": "^11.1.0",
"core-js-bundle": "^3.35.0",
"cross-env": "^7.0.3",
"css-loader": "^6.10.0",
"esbuild": "^0.20.2",
"eslint": "^8.57.0",
"eslint": "^9.17.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-react": "^7.34.4",
"eslint-plugin-security": "^1.7.1",
"eslint-plugin-security": "^3.0.1",
"express": "^4.20.0",
"extract-zip": "^2.0.1",
"fake-indexeddb": "^4.0.2",
Expand Down Expand Up @@ -152,12 +152,17 @@
"webpack-node-externals": "^3.0.0"
},
"dependencies": {
"@eslint/compat": "^1.2.5",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.18.0",
"@eslint/migrate-config": "^1.3.5",
"@fluentui/react": "^8.118.1",
"@microsoft/applicationinsights-web": "^2.8.15",
"@testing-library/user-event": "^14.5.2",
"ajv": "^8.12.0",
"axe-core": "4.10.2",
"classnames": "^2.5.1",
"globals": "^15.0.0",
"idb-keyval": "^6.2.1",
"lodash": "^4.17.21",
"luxon": "^3.5.0",
Expand Down
5 changes: 2 additions & 3 deletions packages/report-e2e-tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const baseModule = require('../../eslintrc.base');
import baseModule from './eslint.config.js';

module.exports = {
...baseModule,
root: true,
Expand Down
139 changes: 139 additions & 0 deletions packages/report-e2e-tests/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
import { fixupPluginRules } from "@eslint/compat";
import { FlatCompat } from "@eslint/eslintrc";
import js from "@eslint/js";
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import _import from "eslint-plugin-import";
import react from "eslint-plugin-react";
import security from "eslint-plugin-security";
import globals from "globals";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [{
ignores: [
"**/node_modules/",
"**/*bundle.js",
"**/dist/",
"**/drop/",
"**/test-results/",
],
}, ...compat.extends(
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
// "plugin:security/recommended",
), {
plugins: {
react,
"@typescript-eslint": typescriptEslint,
security,
import: fixupPluginRules(_import),
},

languageOptions: {
globals: {
...globals.browser,
...globals.node,
},

parser: tsParser,
ecmaVersion: 8,
sourceType: "module",

parserOptions: {
project: [`{./tsconfig.json}`],

ecmaFeatures: {
jsx: true,
},
},
},

settings: {
react: {
version: "detect",
},
},

rules: {
eqeqeq: ["error", "always", {
null: "ignore",
}],

"import/order": ["error", {
alphabetize: {
order: "asc",
caseInsensitive: true,
},
}],

"no-restricted-imports": ["error", {
paths: [{
name: "typemoq",
importNames: ["GlobalMock", "GlobalScope"],
message: "typemoq Global mocks are incompatible with recent versions of @swc/core, see swc-project/swc#5151",
}],
}],

"no-throw-literal": "error",
"react/no-access-state-in-setstate": "error",
"react/no-unused-state": "error",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/require-await": "off",
"@typescript-eslint/no-implied-eval": "off",
"@typescript-eslint/prefer-regexp-exec": "off",
"@typescript-eslint/await-thenable": "off",
"@typescript-eslint/no-floating-promises": "off",
"react/prop-types": "off",
"react/display-name": "off",
"react/no-unescaped-entities": "off",
"react/no-direct-mutation-state": "off",
"security/detect-object-injection": "off",
"no-prototype-builtins": "off",
},
}, {
files: [
"src/tests/**/*",
"tools/**/*",
"pipeline/**/*",
"deploy/**/*",
"**/Gruntfile.js",
],

rules: {
"security/detect-non-literal-regexp": "off",
"security/detect-non-literal-fs-filename": "off",
"security/detect-unsafe-regex": "off",
"security/detect-child-process": "off",
"security/detect-eval-with-expression": "off",
},
}];
Loading
Loading