|
| 1 | +module.exports = { |
| 2 | + env: { |
| 3 | + browser: true, // window object etc part of browser are made available globally. |
| 4 | + es2020: true, // to include BigInt support |
| 5 | + es6: true, |
| 6 | + commonjs: true, |
| 7 | + node: true, |
| 8 | + }, |
| 9 | + /* |
| 10 | + * The order of extending each plugin matters a LOT!! |
| 11 | + * Thus don't change order of items in this array |
| 12 | + * unless you're sure of it. |
| 13 | + */ |
| 14 | + extends: [ |
| 15 | + "plugin:@bigbinary/neeto/recommended", |
| 16 | + "plugin:cypress/recommended", |
| 17 | + "plugin:json/recommended", |
| 18 | + "eslint:recommended", |
| 19 | + "plugin:react/recommended", |
| 20 | + "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/globals", |
| 21 | + "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/imports/order", |
| 22 | + "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/overrides", |
| 23 | + "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/imports/enforced", |
| 24 | + "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/react", |
| 25 | + "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/promise", |
| 26 | + "prettier", |
| 27 | + ], |
| 28 | + settings: { |
| 29 | + react: { version: "detect" }, |
| 30 | + // We need this for the import/extensions rule to work: https://github.com/import-js/eslint-plugin-import#importextensions |
| 31 | + "import/resolver": { |
| 32 | + node: { |
| 33 | + extensions: [".js", ".jsx", ".ts", ".tsx", ".svg", ".json"], |
| 34 | + }, |
| 35 | + }, |
| 36 | + }, |
| 37 | + parserOptions: { |
| 38 | + ecmaFeatures: { jsx: true }, |
| 39 | + ecmaVersion: 2018, |
| 40 | + sourceType: "module", |
| 41 | + }, |
| 42 | + // babel-eslint is deprecated now. This is the latest package. |
| 43 | + parser: "@babel/eslint-parser", |
| 44 | + plugins: [ |
| 45 | + "react", |
| 46 | + "prettier", |
| 47 | + "import", |
| 48 | + "react-hooks", |
| 49 | + "promise", |
| 50 | + "jam3", |
| 51 | + "unused-imports", |
| 52 | + "sonarjs", |
| 53 | + "security", |
| 54 | + "xss", |
| 55 | + "@bigbinary/neeto", |
| 56 | + ], |
| 57 | + rules: { |
| 58 | + // auto-fixable: Respect all Prettier rules and apply it. |
| 59 | + "prettier/prettier": "error", |
| 60 | + // not-auto-fixable: No unused variables allowed. |
| 61 | + "no-unused-vars": [ |
| 62 | + "error", |
| 63 | + { |
| 64 | + args: "all", |
| 65 | + argsIgnorePattern: "^_", |
| 66 | + destructuredArrayIgnorePattern: "^_", |
| 67 | + caughtErrors: "all", |
| 68 | + }, |
| 69 | + ], |
| 70 | + // not-auto-fixable: No undefined variables allowed. |
| 71 | + "no-undef": "error", |
| 72 | + // not-auto-fixable: Dont use console statements. Use logger which babel will remove during bundling. |
| 73 | + "no-console": "error", |
| 74 | + // not-auto-fixable: require `return` statements to either always or never specify values. |
| 75 | + "consistent-return": "error", |
| 76 | + // auto-fixable: disallows repeating variable name when declaring object properties. |
| 77 | + "object-shorthand": "error", |
| 78 | + // auto-fixable: sadly this doesn't support guard clauses yet. |
| 79 | + "padding-line-between-statements": [ |
| 80 | + "error", |
| 81 | + { blankLine: "always", prev: "if", next: ["if", "return"] }, |
| 82 | + // The newline-before-return rule is deprecated in favor of the following: |
| 83 | + { blankLine: "always", prev: "*", next: "return" }, |
| 84 | + // Add newline between function declarations |
| 85 | + { |
| 86 | + blankLine: "always", |
| 87 | + prev: [ |
| 88 | + "block", |
| 89 | + "multiline-block-like", |
| 90 | + "function", |
| 91 | + "iife", |
| 92 | + "multiline-const", |
| 93 | + "multiline-expression", |
| 94 | + ], |
| 95 | + next: ["function", "iife", "multiline-const", "multiline-expression"], |
| 96 | + }, |
| 97 | + ], |
| 98 | + // auto-fixable: Single line statements needn't have any braces. But in all other cases enforce curly braces. |
| 99 | + curly: ["error", "multi-line"], |
| 100 | + // auto-fixable: Remove the else part, if the "if" or "else-if" chain has a return statement |
| 101 | + "no-else-return": "error", |
| 102 | + // not-auto-fixable: Prevent un-sanitized dangerouslySetInnerHTML. |
| 103 | + "jam3/no-sanitizer-with-danger": [ |
| 104 | + 2, |
| 105 | + { wrapperName: ["dompurify", "sanitizer", "sanitize"] }, |
| 106 | + ], |
| 107 | + // auto-fixable: Requires trailing commas when the last element or property is in a different line than the closing ] or } |
| 108 | + "comma-dangle": [ |
| 109 | + "error", |
| 110 | + { |
| 111 | + arrays: "always-multiline", |
| 112 | + objects: "always-multiline", |
| 113 | + imports: "always-multiline", |
| 114 | + exports: "always-multiline", |
| 115 | + functions: "never", |
| 116 | + }, |
| 117 | + ], |
| 118 | + // auto-fixable: If a variable is never reassigned, using the const declaration is better. |
| 119 | + "prefer-const": "error", |
| 120 | + // auto-fixable: It is considered good practice to use the type-safe equality operators === and !==. |
| 121 | + eqeqeq: "error", |
| 122 | + // not-auto-fixable: Rule flags optional chaining expressions in positions where short-circuiting to undefined causes throwing a TypeError afterward. |
| 123 | + "no-unsafe-optional-chaining": "error", |
| 124 | + // auto-fixable: Remove all unused imports. |
| 125 | + "unused-imports/no-unused-imports": "error", |
| 126 | + // auto-fixable-1-level-deep: Using nested ternary operators make the code unreadable. Use if/else or switch with if/else. If it's JSX then move it out into a function or a variable. It's fine to use nestedTernary in JSX when it makes code more readable. |
| 127 | + "no-nested-ternary": "warn", |
| 128 | + // auto-fixable: Enforces no braces where they can be omitted. |
| 129 | + "arrow-body-style": ["error", "as-needed"], |
| 130 | + // auto-fixable: Suggests using template literals instead of string concatenation. |
| 131 | + "prefer-template": "error", |
| 132 | + // auto-fixable: Disallows ternary operators when simpler alternatives exist. |
| 133 | + "no-unneeded-ternary": ["error", { defaultAssignment: false }], |
| 134 | + // not-auto-fixable: Enforces declaring default params last |
| 135 | + "default-param-last": "error", |
| 136 | + // not-auto-fixable: Remove redundant async-awaits |
| 137 | + "no-return-await": "warn", |
| 138 | + // not-auto-fixable: Disallow empty block statements |
| 139 | + "no-empty": ["error", { allowEmptyCatch: true }], |
| 140 | + // not-auto-fixable: Enforce return statements in callbacks of array methods. |
| 141 | + "array-callback-return": ["error"], |
| 142 | + // auto-fixable: Partially fixable. Unless there's a need to the this keyword, there's no advantage of using a plain function. |
| 143 | + "prefer-arrow-callback": ["error", { allowUnboundThis: true }], |
| 144 | + // not-auto-fixable: Convert multiple imports from same module into a single import. |
| 145 | + "no-duplicate-imports": ["error", { includeExports: true }], |
| 146 | + // auto-fixable: Partially fixable. In JavaScript, there are a lot of different ways to convert value types. Allow only readable coercions. |
| 147 | + "no-implicit-coercion": ["error", { allow: ["!!"] }], |
| 148 | + // auto-fixable: Require let or const instead of var. |
| 149 | + "no-var": "error", |
| 150 | + // auto-fixable: This rule conflicts with prettier rules. Thus we've NOT kept this rule in react file. This rule ensures we don't add blank lines in JSX. |
| 151 | + "react/jsx-newline": ["error", { prevent: true }], |
| 152 | + // not-auto-fixable: Disallow async functions which have no await expression |
| 153 | + "require-await": "error", |
| 154 | + // auto-fixable: This rule ensures immediate returns in functions where constants are declared and then directly returned. |
| 155 | + "sonarjs/prefer-immediate-return": "error", |
| 156 | + // not-auto-fixable: This rule enforces merging adjacent collapsible if statements. |
| 157 | + "sonarjs/no-collapsible-if": "error", |
| 158 | + // not-auto-fixable: This rule prevents identical conditions inside if-else statements. |
| 159 | + "sonarjs/no-identical-conditions": "error", |
| 160 | + // not-auto-fixable: This rule prevents using a function with no return as output, passing it to another function, or assigning its result to a variable. |
| 161 | + "sonarjs/no-use-of-empty-return-value": "error", |
| 162 | + // not-auto-fixable: This rule prevents using loops with at most one iteration. |
| 163 | + "sonarjs/no-one-iteration-loop": "error", |
| 164 | + // not-auto-fixable: This rule prevents using catch clause that only throws an error. |
| 165 | + "sonarjs/no-useless-catch": "error", |
| 166 | + // not-auto-fixable: This rule warns against "eval(variable)" which can allow an attacker to run arbitrary code inside your process. |
| 167 | + "security/detect-eval-with-expression": "warn", |
| 168 | + // not-auto-fixable: This rule ensures that you are calling escape function before location.href assignment. |
| 169 | + "xss/no-location-href-assign": ["error", { escapeFunc: "sanitize" }], |
| 170 | + }, |
| 171 | +}; |
0 commit comments