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

chore(repo): migrate to eslint #12620

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fba396e
chore(repo): use typescript 5.0.2 across workspace
HuiSF Nov 14, 2023
2dc051f
chore(repo): unify tsconfig set up across packages
HuiSF Nov 15, 2023
9ab97c0
chore(repo): migrate to eslint
HuiSF Nov 16, 2023
3798c1d
chore(repo): update jest setup script to work with eslint and tsconfig
HuiSF Nov 29, 2023
a3d1e90
chore(adapter-nextjs): run eslint src --fix
HuiSF Nov 17, 2023
d2d35d4
chore(analytics): run eslint --fix
HuiSF Nov 17, 2023
6e1eeca
chore(api): run eslint --fix
HuiSF Nov 17, 2023
b7b39c4
chore(api-rest): run eslint --fix
HuiSF Nov 17, 2023
700a88d
chore(aws-amplify): run eslint --fix
HuiSF Nov 17, 2023
6607c26
chore(core): run eslint --fix
HuiSF Nov 21, 2023
225b71f
chore(storage): run eslint --fix
HuiSF Nov 21, 2023
246e476
chore(rtn-web-browser): run eslint --fix
HuiSF Nov 21, 2023
fc0de6d
chore(rtn-push-notification): run eslint --fix
HuiSF Nov 21, 2023
ee46b65
chore(react-native): run eslint --fix
HuiSF Nov 21, 2023
606ce07
chore(pubsub): run eslint --fix
HuiSF Nov 21, 2023
f7f249f
chore(auth): run eslint --fix
HuiSF Nov 21, 2023
bbb63d9
chore(predictions): run eslint --fix
HuiSF Nov 21, 2023
4d099ac
chore(notifications): run eslint --fix
HuiSF Nov 21, 2023
8f453d3
chore(geo): run eslint --fix
HuiSF Nov 21, 2023
361d7e1
chore(datastore-adapter): run eslint --fix
HuiSF Nov 21, 2023
f143c5e
chore(api-graphql): run eslint --fix
HuiSF Nov 22, 2023
03ab192
chore(interactions): run eslint --fix
HuiSF Nov 22, 2023
4f59ef1
chore(datastore): run eslint --fix
HuiSF Nov 22, 2023
52a1802
fix(repo): using js-yaml load function instead of safeLoad
HuiSF Nov 29, 2023
54a4dd4
chore(repo): remove unused husky config
HuiSF Nov 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
195 changes: 195 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/** @type {import("eslint").ESLint.ConfigData}*/
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
},
extends: [
'eslint:recommended',
'standard',
'plugin:import/errors',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:@typescript-eslint/stylistic',
'plugin:@typescript-eslint/recommended',
'prettier',
],
plugins: [
'@stylistic',
'@typescript-eslint',
'no-relative-import-paths',
'unused-imports',
'import',
'jsdoc',
],
env: {
es6: true,
node: true,
},
ignorePatterns: [
'dist',
'node_modules',
'.eslintrc.*',
'rollup',
'rollup.config.*',
'setupTests.ts',
'jest.setup.*',
'jest.config.*',
// temporarily disable lint on __tests__
'__tests__',
],
rules: {
camelcase: [
'error',
{
allow: [
'graphql_headers',
// exceptions for the legacy config
/^(aws_|amazon_)/,
'access_key',
'secret_key',
'session_token',
// exceptions for the auth package
'redirect_uri',
'response_type',
'client_id',
'identity_provider',
'code_challenge',
'code_challenge_method',
'grant_type',
'code_verifier',
'logout_uri',
'id_token',
'access_token',
'token_type',
'expires_in',
'error_description',
// exceptions for the notifications package
'campaign_id',
'delivery_type',
'treatment_id',
'campaign_activity_id',
],
},
],
'import/no-deprecated': 'warn',
'import/no-empty-named-blocks': 'error',
'import/no-mutable-exports': 'error',
'import/no-relative-packages': 'error',
'import/newline-after-import': 'error',
'import/order': [
'error',
{
groups: [
'builtin',
['external', 'internal', 'parent'],
'sibling',
'index',
'object',
'type',
],
'newlines-between': 'always',
pathGroups: [
{
pattern: '~/**',
group: 'parent',
},
],
},
],
'no-eval': 'error',
'no-param-reassign': 'error',
'no-shadow': 'off',
'no-use-before-define': 'off',
'no-useless-constructor': 'off',
'no-trailing-spaces': 'error',
'no-return-await': 'error',
'object-shorthand': 'error',
'prefer-destructuring': 'off',
'promise/catch-or-return': [
'error',
{ terminationMethod: ['then', 'catch', 'asCallback', 'finally'] },
],
'space-before-function-paren': 'off',
'sort-imports': ['error', { ignoreDeclarationSort: true }],
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'error',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
'valid-typeof': ['error', { requireStringLiterals: false }],
'@stylistic/comma-dangle': [
'error',
{
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'always-multiline',
enums: 'always-multiline',
generics: 'always-multiline',
tuples: 'always-multiline',
},
],
'@stylistic/function-call-argument-newline': ['error', 'consistent'],
'@stylistic/indent': 'off',
'@stylistic/max-len': [
'error',
{
code: 120,
ignoreComments: true,
ignoreUrls: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreRegExpLiterals: true,
},
],
'@stylistic/padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'return' },
],
'@typescript-eslint/method-signature-style': ['error', 'method'],
'@typescript-eslint/no-confusing-void-expression': 'error',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': ['error', { allowDeclarations: true }],
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-use-before-define': [
'error',
{ functions: false, variables: false, classes: false },
],
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/prefer-destructuring': [
'error',
{ object: true, array: false },
],
'@typescript-eslint/space-before-function-paren': [
'error',
{
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
},
],
'jsdoc/no-undefined-types': 1,
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
typescript: {
alwaysTryTypes: true,
project: ['packages/*/tsconfig.json', 'tsconfig.json'],
},
},
'import/ignore': ['react-native'],
},
};
18 changes: 18 additions & 0 deletions .eslintrc.scoped.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This eslintrc is used when running `eslint src` (yarn lint) in the scope of each package in the lerna workspace
// so that the no-relative-import-paths plugin can correctly apply rule checks

/** @type {import("eslint").ESLint.ConfigData}*/
module.exports = {
extends: '.eslintrc.js',
rules: {
'no-relative-import-paths/no-relative-import-paths': [
'error',
{
allowSameFolder: true,
prefix: '~',
// relative to the root of a package itself
rootDir: '.',
},
],
},
};
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ docs
package.json
yarn.lock
package-lock.json
.eslintrc.js
www
.stencil
PULL_REQUEST_TEMPLATE.md
Expand Down
8 changes: 2 additions & 6 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"esbenp.prettier-vscode",
"tombonnike.vscode-status-bar-format-toggle"
"dbaeumer.vscode-eslint",
"streetsidesoftware.code-spell-checker"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
21 changes: 11 additions & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.detectIndentation": false,
"editor.formatOnSave": true,
"editor.insertSpaces": false,
"editor.tabSize": 4,
"prettier.requireConfig": true,
"typescript.tsdk": "node_modules/typescript/lib"
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.detectIndentation": false,
"editor.formatOnSave": true,
"editor.insertSpaces": false,
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to use space in ALL places instead of tabs one day🙏

"editor.tabSize": 4,
"prettier.requireConfig": true,
"typescript.preferences.importModuleSpecifier": "non-relative",
"typescript.tsdk": "node_modules/typescript/lib"
}
25 changes: 0 additions & 25 deletions jest.config.js

This file was deleted.

36 changes: 36 additions & 0 deletions jest/getJestConfig.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import typescript from 'typescript';
import * as tsJest from 'ts-jest';
import deepmerge from 'deepmerge';

/**
* Creates a jest config object by merging typescript compiler options and jest config object into the base jest config.
*
* @param {typescript.CompilerOptions} tsCompilerOptions The compiler options of `tsconfig`.
* @param {tsJest.JestConfigWithTsJest?} jestConfig The jest config to be merged into the base jest config.
* @return {tsJest.JestConfigWithTsJest} The jest config object.
*/
export const getJestConfig = (tsCompilerOptions, jestConfig = {}) =>
deepmerge(
{
workerIdleMemoryLimit: '512MB',
coveragePathIgnorePatterns: ['/node_modules/', 'dist', '__tests__'],
setupFiles: ['../../jest.setup.js'],
testEnvironment: 'jsdom',
testRegex: '/__tests__/.*\\.(test|spec)\\.[jt]sx?$',
transform: {
'^.+\\.(js|jsx|ts|tsx)$': [
'ts-jest',
{
tsconfig: 'tsconfig.test.json',
},
],
},
moduleNameMapper: tsJest.pathsToModuleNameMapper(
tsCompilerOptions.paths,
{
prefix: '<rootDir>/',
},
),
},
jestConfig,
);
11 changes: 11 additions & 0 deletions jest/requireResolve.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createRequire } from 'module';

const require = createRequire(import.meta.url);

/**
* Resolves module path name.
*
* @param {String} moduleName Module name.
* @returns {String} Module path name;
*/
export const requireResolve = moduleName => require.resolve(moduleName);
4 changes: 3 additions & 1 deletion license_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"**/Gemfile",
"**/.rollup.cache",
"**/rollup.config.mjs",
"rollup"
"rollup",
"jest",
"**/jest.config.mjs"
],
"ignoreFile": ".gitignore",
"license": "license_header.txt",
Expand Down
23 changes: 20 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"clean:size": "lerna run clean:size --parallel",
"format": "lerna run format",
"lint": "lerna run lint",
"lint:fix": "lerna run lint:fix",
"lint:license": "license-check-and-add add -f license_config.json",
"link-all": "yarn unlink-all && lerna exec --no-bail --parallel yarn link",
"unlink-all": "lerna exec --no-bail --parallel -- yarn unlink; exit 0",
Expand Down Expand Up @@ -86,12 +87,28 @@
"@size-limit/file": "^8.1.0",
"@size-limit/webpack": "^8.1.0",
"@size-limit/webpack-why": "^8.1.0",
"@stylistic/eslint-plugin": "^1.4.0",
"@types/jest": "^29.5.8",
"@types/lodash": "4.14.182",
"@types/node": "^8.9.5",
"@types/puppeteer": "1.3.0",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"babel-jest": "^24.9.0",
"babel-loader": "^8.3.0",
"codecov": "^3.6.5",
"cross-env": "^7.0.3",
"deepmerge": "^4.3.1",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-standard": "^17.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsdoc": "^46.9.0",
"eslint-plugin-n": "^16.3.1",
"eslint-plugin-no-relative-import-paths": "^1.5.3",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-unused-imports": "^3.0.0",
"glob": "^10.3.10",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
Expand All @@ -110,11 +127,11 @@
"terser-webpack-plugin": "^5.3.6",
"ts-jest": "^29.1.1",
"ts-loader": "^9.4.3",
"tslint": "^5.7.0",
"tslint-config-airbnb": "^5.8.0",
"ts-patch": "^3.0.2",
"typedoc": "^0.17.0",
"typescript": "^4.3.5",
"typescript": "~5.0.2",
"typescript-coverage-report": "^0.6.4",
"typescript-transform-paths": "^3.4.6",
"uuid-validate": "^0.0.3",
"webpack": "^5.75.0",
"webpack-bundle-analyzer": "^4.7.0",
Expand Down
Loading
Loading