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

Eslint upgrade to v9 #9538

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9e6a401
Eslint upgrade to v9
amjithtitus09 Dec 9, 2024
a3809fd
Merge branch 'develop' into issues/9050/eslint-upgrade-v9
amjithtitus09 Dec 9, 2024
489e7df
Merge branch 'ohcnetwork:develop' into issues/9050/eslint-upgrade-v9
amjithtitus09 Dec 11, 2024
1666d57
Merge branch 'ohcnetwork:develop' into issues/9050/eslint-upgrade-v9
amjithtitus09 Dec 11, 2024
8e7b48f
Remove eslint-mdx dependency, eslint-config-prettier explicit config
amjithtitus09 Dec 11, 2024
00663e2
Merge branch 'develop' into issues/9050/eslint-upgrade-v9
amjithtitus09 Dec 11, 2024
190447e
Remove eslint-plugin-markdown, reverted few lint debug changes in Ass…
amjithtitus09 Dec 11, 2024
95c49ad
Merge branch 'develop' into issues/9050/eslint-upgrade-v9
amjithtitus09 Dec 11, 2024
ebffe86
Merge branch 'develop' into issues/9050/eslint-upgrade-v9
amjithtitus09 Dec 13, 2024
eb5728a
Merge branch 'ohcnetwork:develop' into issues/9050/eslint-upgrade-v9
amjithtitus09 Dec 16, 2024
ffa6d1a
Turn off no-undef as TypeScript handles it, lint --fix
amjithtitus09 Dec 16, 2024
40db612
Merge remote-tracking branch 'origin/develop' into issues/9050/eslint…
sainak Dec 20, 2024
5ceeaba
Fix lint errors, allow short circuit evaluations and ternary operators
amjithtitus09 Dec 23, 2024
ac41cc1
Merge branch develop into issues/9050/eslint-upgrade-v9-new
amjithtitus09 Dec 23, 2024
1528262
Merge branch develop into issues/9050/eslint-upgrade-v9-new
amjithtitus09 Dec 23, 2024
3ef810f
Update package-lock.json
amjithtitus09 Dec 23, 2024
c2ed879
Merge branch 'develop' into issues/9050/eslint-upgrade-v9-new
amjithtitus09 Dec 23, 2024
83237fb
Undo lint error manual fix
amjithtitus09 Dec 23, 2024
7dd8c1d
Merge branch 'ohcnetwork:develop' into issues/9050/eslint-upgrade-v9-new
amjithtitus09 Dec 23, 2024
5adfdb0
Merge branch 'issues/9050/eslint-upgrade-v9-new' of https://github.co…
amjithtitus09 Dec 23, 2024
49e8010
cypress test fix for asset homepage
nihal467 Dec 24, 2024
0c98659
Revert fixes for react/no-children-prop errors, disable rule temporarily
amjithtitus09 Dec 24, 2024
bde2165
Merge branch 'ohcnetwork:develop' into issues/9050/eslint-upgrade-v9-new
amjithtitus09 Dec 24, 2024
5032b6a
Merge branch 'issues/9050/eslint-upgrade-v9-new' of https://github.co…
amjithtitus09 Dec 24, 2024
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
94 changes: 0 additions & 94 deletions .eslintrc.json

This file was deleted.

15 changes: 4 additions & 11 deletions cypress/pageobject/Asset/AssetHome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,13 @@ export class AssetHome {
}

selectImportFacility(facilityName: string) {
cy.get("input[name='facilities']")
.type(facilityName)
.then(() => {
cy.get("[role='option']").contains(facilityName).click();
});
cy.typeAndSelectOption("input[name='facilities']", facilityName);
}

selectAssetImportButton(action: "click" | "verifyNotExist"): void {
const selector = "[data-testid=import-asset-button]";
if (action === "click") {
cy.get(selector).scrollIntoView().should("be.visible").click();
cy.verifyAndClickElement(selector, "Import/Export");
} else if (action === "verifyNotExist") {
cy.get(selector).should("not.exist");
}
Expand Down Expand Up @@ -98,15 +94,12 @@ export class AssetHome {
}

selectImportLocation(locationName: string) {
cy.clickAndSelectOption(
"[data-testid=select-import-location]",
locationName,
);
cy.clickAndSelectOption("#asset-import-location", locationName);
}

clickImportAsset() {
cy.intercept("POST", "**/api/v1/asset/").as("importAsset");
cy.clickSubmitButton("Import");
cy.clickSubmitButton("Submit");
cy.wait("@importAsset").its("response.statusCode").should("eq", 201);
}
}
2 changes: 1 addition & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Cypress.Commands.add("getAttached", (selector: string) => {
$el = getElement(Cypress.$($d));
// Ensure $el is an HTMLElement before checking if it is detached
if ($el.length && $el[0] instanceof HTMLElement) {
expect(Cypress.dom.isDetached($el[0])).to.be.false; // Access the first HTMLElement
expect(Cypress.dom.isDetached($el[0])).to.equal(false); // Access the first HTMLElement
} else {
throw new Error("Element is not an HTMLElement or is detached.");
}
Expand Down
136 changes: 136 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import eslint from "@eslint/js";
import tseslint from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import i18nextPlugin from "eslint-plugin-i18next";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
import reactPlugin from "eslint-plugin-react";
import reactHooksPlugin from "eslint-plugin-react-hooks";
import globals from "globals";


export default [
// Base configuration
{
ignores: [
"**/dist",
"**/public",
"**/lib",
"**/build",
"**/*.css",
"**/*.csv",
"**/Dockerfile",
],
},
eslint.configs.recommended,

// Global settings for all JavaScript/TypeScript files
{
files: ["**/*.{js,jsx,ts,tsx,mjs,mts}"],
languageOptions: {
ecmaVersion: 12,
sourceType: "module",
globals: {
...globals.browser,
...globals.node,
React: true,
},
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
settings: {
react: {
version: "detect",
},
},
linterOptions: {
reportUnusedDisableDirectives: true,
},
},

// TypeScript-specific rules
{
files: ["**/*.{ts,tsx}"],
plugins: {
"@typescript-eslint": tseslint,
},
languageOptions: {
parser: tsParser,
parserOptions: {
project: "./tsconfig.json",
},
},
rules: {
...tseslint.configs.recommended.rules,
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
"@typescript-eslint/no-unused-expressions": [
"error",
{ allowShortCircuit: true, allowTernary: true },
],
"@typescript-eslint/no-explicit-any": "warn",
"no-undef": "off",
},
},
Comment on lines +54 to +82
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Update TypeScript configuration path in ESLint config

The current ./tsconfig.json reference in the ESLint configuration needs to be updated as there are two separate TypeScript configurations:

  1. ./tsconfig.json - Main config for the application source code
  2. ./cypress/tsconfig.json - Specific config for Cypress tests

Since Cypress has its own TypeScript configuration with different settings (e.g., different target, lib, and includes), the ESLint config should be split to handle both contexts separately. Add a new configuration object for Cypress files:

{
  files: ["cypress/**/*.{ts,tsx}"],
  plugins: {
    "@typescript-eslint": tseslint,
  },
  languageOptions: {
    parser: tsParser,
    parserOptions: {
      project: "./cypress/tsconfig.json",
    },
  },
  // ... rest of the rules
},
{
  files: ["src/**/*.{ts,tsx}", "apps/**/*.{ts,tsx}"],
  plugins: {
    "@typescript-eslint": tseslint,
  },
  languageOptions: {
    parser: tsParser,
    parserOptions: {
      project: "./tsconfig.json",
    },
  },
  // ... existing rules
}
🔗 Analysis chain

Verify TypeScript configuration path

The TypeScript configuration references ./tsconfig.json, which might cause issues with Cypress tests. Consider using a more specific path resolution:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for tsconfig files and their references
fd tsconfig.json --type f --exec echo "Found tsconfig: {}"

# Verify if the TypeScript configuration is properly resolved
ast-grep --pattern 'project: $path' | while read -r line; do
  echo "Checking TypeScript project reference: $line"
done

Length of output: 185


Script:

#!/bin/bash
# Check the content of both tsconfig files to understand their relationship
echo "Main tsconfig.json:"
cat ./tsconfig.json

echo -e "\nCypress tsconfig.json:"
cat ./cypress/tsconfig.json

# Check if there are any TypeScript files under cypress directory
fd -e ts -e tsx . cypress/ --type f

Length of output: 4498


// React-specific rules
{
files: ["**/*.{jsx,tsx}"],
plugins: {
react: reactPlugin,
"react-hooks": reactHooksPlugin,
},
rules: {
...reactPlugin.configs.recommended.rules,
...reactHooksPlugin.configs.recommended.rules,
"react/prop-types": "off",
"react/no-children-prop": "off",
},
},

// i18next plugin rules
{
files: ["**/*.{js,jsx,ts,tsx}"],
plugins: {
i18next: i18nextPlugin,
},
rules: {
...i18nextPlugin.configs.recommended.rules,
"i18next/no-literal-string": [
"warn",
{
mode: "jsx-only",
"jsx-attributes": {
include: ["label", "placeholder", "error", "title"],
exclude: [".*"],
},
callees: {
exclude: [".*"],
},
},
],
},
},
Comment on lines +99 to +121
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refine i18next exclude patterns

The current exclude patterns using ".*" are too permissive and might miss untranslated strings. Consider listing specific exclusions:

  "jsx-attributes": {
    include: ["label", "placeholder", "error", "title"],
-   exclude: [".*"],
+   exclude: ["data-testid", "className", "style", "key", "id", "type", "name"],
  },
  callees: {
-   exclude: [".*"],
+   exclude: ["console.log", "console.error", "test", "describe", "it"],
  },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// i18next plugin rules
{
files: ["**/*.{js,jsx,ts,tsx}"],
plugins: {
i18next: i18nextPlugin,
},
rules: {
...i18nextPlugin.configs.recommended.rules,
"i18next/no-literal-string": [
"warn",
{
mode: "jsx-only",
"jsx-attributes": {
include: ["label", "placeholder", "error", "title"],
exclude: [".*"],
},
callees: {
exclude: [".*"],
},
},
],
},
},
// i18next plugin rules
{
files: ["**/*.{js,jsx,ts,tsx}"],
plugins: {
i18next: i18nextPlugin,
},
rules: {
...i18nextPlugin.configs.recommended.rules,
"i18next/no-literal-string": [
"warn",
{
mode: "jsx-only",
"jsx-attributes": {
include: ["label", "placeholder", "error", "title"],
exclude: ["data-testid", "className", "style", "key", "id", "type", "name"],
},
callees: {
exclude: ["console.log", "console.error", "test", "describe", "it"],
},
},
],
},
},


// Cypress-specific rules
{
files: ["cypress/**/*.ts"],
languageOptions: {
parser: tsParser,
parserOptions: {
project: "./cypress/tsconfig.json",
},
},
},

// Add prettier recommended config last
eslintPluginPrettierRecommended,
];
Loading
Loading