Skip to content

Commit ed06e2e

Browse files
Removed unwanted configurations
1 parent dddf050 commit ed06e2e

File tree

8 files changed

+406
-3
lines changed

8 files changed

+406
-3
lines changed

.eslintrc.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
1-
const defaultConfigurations = require("@bigbinary/neeto-commons-frontend/configs/nanos/eslint/index.js");
2-
const { mergeDeepLeft } = require("ramda");
1+
const { mergeLeft, mergeDeepLeft } = require("ramda");
2+
3+
const commonConfiguration = require("./configs/eslint");
4+
5+
const nanosConfiguration = {
6+
extends: [
7+
"plugin:@bigbinary/neeto/nanos-recommended",
8+
"plugin:cypress/recommended",
9+
"plugin:json/recommended",
10+
"eslint:recommended",
11+
"plugin:react/recommended",
12+
`./configs/eslint/globals`,
13+
`./configs/eslint/overrides`,
14+
`./configs/eslint/imports/enforced`,
15+
`./configs/eslint/react`,
16+
`./configs/eslint/promise`,
17+
"prettier",
18+
],
19+
};
20+
21+
const defaultConfigurations = mergeLeft(
22+
nanosConfiguration,
23+
commonConfiguration
24+
);
325

426
module.exports = mergeDeepLeft(
527
{

babel.config.js

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,53 @@
1-
module.exports = require("@bigbinary/neeto-commons-frontend/configs/babel.js");
1+
// eslint-disable-next-line @bigbinary/neeto/no-dangling-constants
2+
const VALID_ENVIRONMENTS = ["development", "test", "production"];
3+
4+
module.exports = function (api) {
5+
const currentEnv = api.env();
6+
const isDevelopmentEnv = api.env("development");
7+
const isProductionEnv = api.env("production");
8+
const isTestEnv = api.env("test");
9+
10+
if (!VALID_ENVIRONMENTS.includes(currentEnv)) {
11+
throw new Error(
12+
"Please specify a valid `NODE_ENV` or `BABEL_ENV` environment variables. " +
13+
'Valid values are "development", "test", and "production". ' +
14+
`Instead, received: ${JSON.stringify(currentEnv)}.`
15+
);
16+
}
17+
18+
return {
19+
presets: [
20+
isTestEnv
21+
? [
22+
"@babel/preset-env",
23+
{ targets: { node: "current" }, modules: "commonjs" },
24+
]
25+
: [
26+
"@babel/preset-env",
27+
{
28+
forceAllTransforms: isProductionEnv,
29+
useBuiltIns: "entry",
30+
corejs: "3.27.0",
31+
modules: false,
32+
},
33+
],
34+
[
35+
"@babel/preset-react",
36+
{ development: isDevelopmentEnv || isTestEnv, runtime: "automatic" },
37+
],
38+
"@bigbinary/neeto",
39+
].filter(Boolean),
40+
plugins: [
41+
"preval",
42+
"babel-plugin-macros",
43+
"@babel/plugin-transform-runtime",
44+
isTestEnv
45+
? "babel-plugin-dynamic-import-node" // tests run in node environment
46+
: "@babel/plugin-syntax-dynamic-import",
47+
isProductionEnv && [
48+
"babel-plugin-transform-react-remove-prop-types",
49+
{ removeImport: true },
50+
],
51+
].filter(Boolean),
52+
};
53+
};

configs/eslint/globals.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
// Globals can be disabled with the string "off"
3+
// "writable" to allow the variable to be overwritten or "readonly" to disallow overwriting.
4+
globals: {
5+
Atomics: "readonly",
6+
SharedArrayBuffer: "readonly",
7+
// Makes logger function available everywhere. Else eslint will complaint of undef-var.
8+
logger: "readonly",
9+
module: "writable",
10+
// Makes props obtained from Rails backend available everywhere in this project.
11+
globalProps: "readonly",
12+
preval: "readonly",
13+
},
14+
};

configs/eslint/imports/enforced.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
rules: {
3+
// not-auto-fixable: Prefer a default export if module exports a single name.
4+
"import/prefer-default-export": "off",
5+
// not-auto-fixable: Forbid a module from importing a module with a dependency path back to itself.
6+
"import/no-cycle": ["warn", { maxDepth: 1, ignoreExternal: true }],
7+
// not-auto-fixable: Prevent unnecessary path segments in import and require statements.
8+
"import/no-useless-path-segments": ["error", { noUselessIndex: true }],
9+
// not-auto-fixable: Report any invalid exports, i.e. re-export of the same name.
10+
"import/export": "error",
11+
// not-auto-fixable: Forbid the use of mutable exports with var or let.
12+
"import/no-mutable-exports": "error",
13+
// not-auto-fixable: Ensure all imports appear before other statements.
14+
"import/first": "error",
15+
// not-auto-fixable: Ensure all exports appear after other statements.
16+
"import/exports-last": "error",
17+
// auto-fixable: Enforce a newline after import statements.
18+
"import/newline-after-import": ["error", { count: 1 }],
19+
// auto-fixable: Remove file extensions for import statements.
20+
"import/extensions": [
21+
"error",
22+
"never",
23+
{
24+
ignorePackages: true,
25+
pattern: { json: "always", ico: "always", yml: "always" },
26+
},
27+
],
28+
},
29+
};

configs/eslint/index.js

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
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+
};

configs/eslint/overrides.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
// Currently we are using this section for excluding certain files from certain rules.
3+
overrides: [
4+
{
5+
files: [".eslintrc.js", ".prettierrc.js", "*.json"],
6+
rules: {
7+
"import/order": "off",
8+
"react-hooks/rules-of-hooks": "off",
9+
},
10+
},
11+
{ files: ["src/**/.js"], rules: { "no-redeclare": "off" } },
12+
{
13+
files: ["**/*.spec.js", "**/*.spec.jsx", "**/*.test.jsx"],
14+
env: { jest: true },
15+
},
16+
],
17+
};

configs/eslint/promise.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
rules: {
3+
// not-auto-fixable: ensure people use async/await promising chaining rather than using "then-catch-finally" statements
4+
"promise/prefer-await-to-then": "error",
5+
// auto-fixable: avoid calling "new" on a Promise static method like reject, resolve etc
6+
"promise/no-new-statics": "error",
7+
},
8+
};

0 commit comments

Comments
 (0)