Skip to content

Commit

Permalink
chore(repo): setup eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiSF committed Jan 29, 2024
1 parent 3c7333b commit 791c8f4
Show file tree
Hide file tree
Showing 7 changed files with 1,278 additions and 33 deletions.
190 changes: 190 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
/** @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',
'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__',
// will enable lint by packages
// 'adapter-nextjs',
'analytics',
'api',
'api-graphql',
'auth',
'aws-amplify',
'core',
'datastore',
'datastore-storage-adapter',
'geo',
'interactions',
'notifications',
'predictions',
'pubsub',
'react-native',
'rtn-push-notification',
'rtn-web-browser',
'storage',
],
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', { 'newlines-between': 'always' }],
'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'],
},
};
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
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"esbenp.prettier-vscode",
"tombonnike.vscode-status-bar-format-toggle"
"tombonnike.vscode-status-bar-format-toggle",
"dbaeumer.vscode-eslint"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
Expand Down
10 changes: 4 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"[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"
"typescript.tsdk": "node_modules/typescript/lib",
"formattingToggle.affects": [
"editor.codeActionsOnSave.source.fixAll.eslint"
]
}
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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,11 +87,23 @@
"@size-limit/file": "^8.1.0",
"@size-limit/webpack": "^8.1.0",
"@size-limit/webpack-why": "^8.1.0",
"@stylistic/eslint-plugin": "^1.5.4",
"@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.20.0",
"@typescript-eslint/parser": "^6.20.0",
"babel-loader": "^8.3.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^17.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsdoc": "^48.0.4",
"eslint-plugin-n": "^16.6.2",
"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 Down
3 changes: 2 additions & 1 deletion prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @type {import('prettier').Config} */
module.exports = {
trailingComma: 'es5',
trailingComma: 'all',
printWidth: 80,
singleQuote: true,
useTabs: true,
arrowParens: 'avoid',
Expand Down
Loading

0 comments on commit 791c8f4

Please sign in to comment.