-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dddf050
commit ed06e2e
Showing
8 changed files
with
406 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,53 @@ | ||
module.exports = require("@bigbinary/neeto-commons-frontend/configs/babel.js"); | ||
// eslint-disable-next-line @bigbinary/neeto/no-dangling-constants | ||
const VALID_ENVIRONMENTS = ["development", "test", "production"]; | ||
|
||
module.exports = function (api) { | ||
const currentEnv = api.env(); | ||
const isDevelopmentEnv = api.env("development"); | ||
const isProductionEnv = api.env("production"); | ||
const isTestEnv = api.env("test"); | ||
|
||
if (!VALID_ENVIRONMENTS.includes(currentEnv)) { | ||
throw new Error( | ||
"Please specify a valid `NODE_ENV` or `BABEL_ENV` environment variables. " + | ||
'Valid values are "development", "test", and "production". ' + | ||
`Instead, received: ${JSON.stringify(currentEnv)}.` | ||
); | ||
} | ||
|
||
return { | ||
presets: [ | ||
isTestEnv | ||
? [ | ||
"@babel/preset-env", | ||
{ targets: { node: "current" }, modules: "commonjs" }, | ||
] | ||
: [ | ||
"@babel/preset-env", | ||
{ | ||
forceAllTransforms: isProductionEnv, | ||
useBuiltIns: "entry", | ||
corejs: "3.27.0", | ||
modules: false, | ||
}, | ||
], | ||
[ | ||
"@babel/preset-react", | ||
{ development: isDevelopmentEnv || isTestEnv, runtime: "automatic" }, | ||
], | ||
"@bigbinary/neeto", | ||
].filter(Boolean), | ||
plugins: [ | ||
"preval", | ||
"babel-plugin-macros", | ||
"@babel/plugin-transform-runtime", | ||
isTestEnv | ||
? "babel-plugin-dynamic-import-node" // tests run in node environment | ||
: "@babel/plugin-syntax-dynamic-import", | ||
isProductionEnv && [ | ||
"babel-plugin-transform-react-remove-prop-types", | ||
{ removeImport: true }, | ||
], | ||
].filter(Boolean), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = { | ||
// Globals can be disabled with the string "off" | ||
// "writable" to allow the variable to be overwritten or "readonly" to disallow overwriting. | ||
globals: { | ||
Atomics: "readonly", | ||
SharedArrayBuffer: "readonly", | ||
// Makes logger function available everywhere. Else eslint will complaint of undef-var. | ||
logger: "readonly", | ||
module: "writable", | ||
// Makes props obtained from Rails backend available everywhere in this project. | ||
globalProps: "readonly", | ||
preval: "readonly", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module.exports = { | ||
rules: { | ||
// not-auto-fixable: Prefer a default export if module exports a single name. | ||
"import/prefer-default-export": "off", | ||
// not-auto-fixable: Forbid a module from importing a module with a dependency path back to itself. | ||
"import/no-cycle": ["warn", { maxDepth: 1, ignoreExternal: true }], | ||
// not-auto-fixable: Prevent unnecessary path segments in import and require statements. | ||
"import/no-useless-path-segments": ["error", { noUselessIndex: true }], | ||
// not-auto-fixable: Report any invalid exports, i.e. re-export of the same name. | ||
"import/export": "error", | ||
// not-auto-fixable: Forbid the use of mutable exports with var or let. | ||
"import/no-mutable-exports": "error", | ||
// not-auto-fixable: Ensure all imports appear before other statements. | ||
"import/first": "error", | ||
// not-auto-fixable: Ensure all exports appear after other statements. | ||
"import/exports-last": "error", | ||
// auto-fixable: Enforce a newline after import statements. | ||
"import/newline-after-import": ["error", { count: 1 }], | ||
// auto-fixable: Remove file extensions for import statements. | ||
"import/extensions": [ | ||
"error", | ||
"never", | ||
{ | ||
ignorePackages: true, | ||
pattern: { json: "always", ico: "always", yml: "always" }, | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, // window object etc part of browser are made available globally. | ||
es2020: true, // to include BigInt support | ||
es6: true, | ||
commonjs: true, | ||
node: true, | ||
}, | ||
/* | ||
* The order of extending each plugin matters a LOT!! | ||
* Thus don't change order of items in this array | ||
* unless you're sure of it. | ||
*/ | ||
extends: [ | ||
"plugin:@bigbinary/neeto/recommended", | ||
"plugin:cypress/recommended", | ||
"plugin:json/recommended", | ||
"eslint:recommended", | ||
"plugin:react/recommended", | ||
"./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/globals", | ||
"./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/imports/order", | ||
"./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/overrides", | ||
"./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/imports/enforced", | ||
"./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/react", | ||
"./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/promise", | ||
"prettier", | ||
], | ||
settings: { | ||
react: { version: "detect" }, | ||
// We need this for the import/extensions rule to work: https://github.com/import-js/eslint-plugin-import#importextensions | ||
"import/resolver": { | ||
node: { | ||
extensions: [".js", ".jsx", ".ts", ".tsx", ".svg", ".json"], | ||
}, | ||
}, | ||
}, | ||
parserOptions: { | ||
ecmaFeatures: { jsx: true }, | ||
ecmaVersion: 2018, | ||
sourceType: "module", | ||
}, | ||
// babel-eslint is deprecated now. This is the latest package. | ||
parser: "@babel/eslint-parser", | ||
plugins: [ | ||
"react", | ||
"prettier", | ||
"import", | ||
"react-hooks", | ||
"promise", | ||
"jam3", | ||
"unused-imports", | ||
"sonarjs", | ||
"security", | ||
"xss", | ||
"@bigbinary/neeto", | ||
], | ||
rules: { | ||
// auto-fixable: Respect all Prettier rules and apply it. | ||
"prettier/prettier": "error", | ||
// not-auto-fixable: No unused variables allowed. | ||
"no-unused-vars": [ | ||
"error", | ||
{ | ||
args: "all", | ||
argsIgnorePattern: "^_", | ||
destructuredArrayIgnorePattern: "^_", | ||
caughtErrors: "all", | ||
}, | ||
], | ||
// not-auto-fixable: No undefined variables allowed. | ||
"no-undef": "error", | ||
// not-auto-fixable: Dont use console statements. Use logger which babel will remove during bundling. | ||
"no-console": "error", | ||
// not-auto-fixable: require `return` statements to either always or never specify values. | ||
"consistent-return": "error", | ||
// auto-fixable: disallows repeating variable name when declaring object properties. | ||
"object-shorthand": "error", | ||
// auto-fixable: sadly this doesn't support guard clauses yet. | ||
"padding-line-between-statements": [ | ||
"error", | ||
{ blankLine: "always", prev: "if", next: ["if", "return"] }, | ||
// The newline-before-return rule is deprecated in favor of the following: | ||
{ blankLine: "always", prev: "*", next: "return" }, | ||
// Add newline between function declarations | ||
{ | ||
blankLine: "always", | ||
prev: [ | ||
"block", | ||
"multiline-block-like", | ||
"function", | ||
"iife", | ||
"multiline-const", | ||
"multiline-expression", | ||
], | ||
next: ["function", "iife", "multiline-const", "multiline-expression"], | ||
}, | ||
], | ||
// auto-fixable: Single line statements needn't have any braces. But in all other cases enforce curly braces. | ||
curly: ["error", "multi-line"], | ||
// auto-fixable: Remove the else part, if the "if" or "else-if" chain has a return statement | ||
"no-else-return": "error", | ||
// not-auto-fixable: Prevent un-sanitized dangerouslySetInnerHTML. | ||
"jam3/no-sanitizer-with-danger": [ | ||
2, | ||
{ wrapperName: ["dompurify", "sanitizer", "sanitize"] }, | ||
], | ||
// auto-fixable: Requires trailing commas when the last element or property is in a different line than the closing ] or } | ||
"comma-dangle": [ | ||
"error", | ||
{ | ||
arrays: "always-multiline", | ||
objects: "always-multiline", | ||
imports: "always-multiline", | ||
exports: "always-multiline", | ||
functions: "never", | ||
}, | ||
], | ||
// auto-fixable: If a variable is never reassigned, using the const declaration is better. | ||
"prefer-const": "error", | ||
// auto-fixable: It is considered good practice to use the type-safe equality operators === and !==. | ||
eqeqeq: "error", | ||
// not-auto-fixable: Rule flags optional chaining expressions in positions where short-circuiting to undefined causes throwing a TypeError afterward. | ||
"no-unsafe-optional-chaining": "error", | ||
// auto-fixable: Remove all unused imports. | ||
"unused-imports/no-unused-imports": "error", | ||
// 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. | ||
"no-nested-ternary": "warn", | ||
// auto-fixable: Enforces no braces where they can be omitted. | ||
"arrow-body-style": ["error", "as-needed"], | ||
// auto-fixable: Suggests using template literals instead of string concatenation. | ||
"prefer-template": "error", | ||
// auto-fixable: Disallows ternary operators when simpler alternatives exist. | ||
"no-unneeded-ternary": ["error", { defaultAssignment: false }], | ||
// not-auto-fixable: Enforces declaring default params last | ||
"default-param-last": "error", | ||
// not-auto-fixable: Remove redundant async-awaits | ||
"no-return-await": "warn", | ||
// not-auto-fixable: Disallow empty block statements | ||
"no-empty": ["error", { allowEmptyCatch: true }], | ||
// not-auto-fixable: Enforce return statements in callbacks of array methods. | ||
"array-callback-return": ["error"], | ||
// auto-fixable: Partially fixable. Unless there's a need to the this keyword, there's no advantage of using a plain function. | ||
"prefer-arrow-callback": ["error", { allowUnboundThis: true }], | ||
// not-auto-fixable: Convert multiple imports from same module into a single import. | ||
"no-duplicate-imports": ["error", { includeExports: true }], | ||
// auto-fixable: Partially fixable. In JavaScript, there are a lot of different ways to convert value types. Allow only readable coercions. | ||
"no-implicit-coercion": ["error", { allow: ["!!"] }], | ||
// auto-fixable: Require let or const instead of var. | ||
"no-var": "error", | ||
// 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. | ||
"react/jsx-newline": ["error", { prevent: true }], | ||
// not-auto-fixable: Disallow async functions which have no await expression | ||
"require-await": "error", | ||
// auto-fixable: This rule ensures immediate returns in functions where constants are declared and then directly returned. | ||
"sonarjs/prefer-immediate-return": "error", | ||
// not-auto-fixable: This rule enforces merging adjacent collapsible if statements. | ||
"sonarjs/no-collapsible-if": "error", | ||
// not-auto-fixable: This rule prevents identical conditions inside if-else statements. | ||
"sonarjs/no-identical-conditions": "error", | ||
// 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. | ||
"sonarjs/no-use-of-empty-return-value": "error", | ||
// not-auto-fixable: This rule prevents using loops with at most one iteration. | ||
"sonarjs/no-one-iteration-loop": "error", | ||
// not-auto-fixable: This rule prevents using catch clause that only throws an error. | ||
"sonarjs/no-useless-catch": "error", | ||
// not-auto-fixable: This rule warns against "eval(variable)" which can allow an attacker to run arbitrary code inside your process. | ||
"security/detect-eval-with-expression": "warn", | ||
// not-auto-fixable: This rule ensures that you are calling escape function before location.href assignment. | ||
"xss/no-location-href-assign": ["error", { escapeFunc: "sanitize" }], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
// Currently we are using this section for excluding certain files from certain rules. | ||
overrides: [ | ||
{ | ||
files: [".eslintrc.js", ".prettierrc.js", "*.json"], | ||
rules: { | ||
"import/order": "off", | ||
"react-hooks/rules-of-hooks": "off", | ||
}, | ||
}, | ||
{ files: ["src/**/.js"], rules: { "no-redeclare": "off" } }, | ||
{ | ||
files: ["**/*.spec.js", "**/*.spec.jsx", "**/*.test.jsx"], | ||
env: { jest: true }, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
rules: { | ||
// not-auto-fixable: ensure people use async/await promising chaining rather than using "then-catch-finally" statements | ||
"promise/prefer-await-to-then": "error", | ||
// auto-fixable: avoid calling "new" on a Promise static method like reject, resolve etc | ||
"promise/no-new-statics": "error", | ||
}, | ||
}; |
Oops, something went wrong.