Skip to content

Commit 872d825

Browse files
committed
chore(repo): setup eslint
1 parent dd497d0 commit 872d825

7 files changed

+1312
-33
lines changed

.eslintrc.js

+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
/** @type {import("eslint").ESLint.ConfigData}*/
2+
module.exports = {
3+
root: true,
4+
parser: '@typescript-eslint/parser',
5+
parserOptions: {
6+
project: './tsconfig.json',
7+
},
8+
extends: [
9+
'eslint:recommended',
10+
'standard',
11+
'plugin:import/errors',
12+
'plugin:import/recommended',
13+
'plugin:import/typescript',
14+
'plugin:@typescript-eslint/stylistic',
15+
'plugin:@typescript-eslint/recommended',
16+
"plugin:prettier/recommended",
17+
],
18+
plugins: [
19+
'@stylistic',
20+
'@typescript-eslint',
21+
'unused-imports',
22+
'import',
23+
'jsdoc',
24+
],
25+
env: {
26+
es6: true,
27+
node: true,
28+
},
29+
ignorePatterns: [
30+
'dist',
31+
'node_modules',
32+
'.eslintrc.*',
33+
'rollup',
34+
'rollup.config.*',
35+
'setupTests.ts',
36+
'jest.setup.*',
37+
'jest.config.*',
38+
// temporarily disable lint on __tests__
39+
'__tests__',
40+
// will enable lint by packages
41+
// 'adapter-nextjs',
42+
'analytics',
43+
'api',
44+
'api-graphql',
45+
'auth',
46+
'aws-amplify',
47+
'core',
48+
'datastore',
49+
'datastore-storage-adapter',
50+
'geo',
51+
'interactions',
52+
'notifications',
53+
'predictions',
54+
'pubsub',
55+
'react-native',
56+
'rtn-push-notification',
57+
'rtn-web-browser',
58+
'storage',
59+
],
60+
rules: {
61+
camelcase: [
62+
'error',
63+
{
64+
allow: [
65+
'graphql_headers',
66+
// exceptions for the legacy config
67+
/^(aws_|amazon_)/,
68+
'access_key',
69+
'secret_key',
70+
'session_token',
71+
// exceptions for the auth package
72+
'redirect_uri',
73+
'response_type',
74+
'client_id',
75+
'identity_provider',
76+
'code_challenge',
77+
'code_challenge_method',
78+
'grant_type',
79+
'code_verifier',
80+
'logout_uri',
81+
'id_token',
82+
'access_token',
83+
'token_type',
84+
'expires_in',
85+
'error_description',
86+
// exceptions for the notifications package
87+
'campaign_id',
88+
'delivery_type',
89+
'treatment_id',
90+
'campaign_activity_id',
91+
],
92+
},
93+
],
94+
'import/no-deprecated': 'warn',
95+
'import/no-empty-named-blocks': 'error',
96+
'import/no-mutable-exports': 'error',
97+
'import/no-relative-packages': 'error',
98+
'import/newline-after-import': 'error',
99+
'import/order': ['error', { 'newlines-between': 'always' }],
100+
'no-eval': 'error',
101+
'no-param-reassign': 'error',
102+
'no-shadow': 'off',
103+
'no-use-before-define': 'off',
104+
'no-useless-constructor': 'off',
105+
'no-trailing-spaces': 'error',
106+
'no-return-await': 'error',
107+
'object-shorthand': 'error',
108+
'prefer-destructuring': 'off',
109+
'promise/catch-or-return': [
110+
'error',
111+
{ terminationMethod: ['then', 'catch', 'asCallback', 'finally'] },
112+
],
113+
'space-before-function-paren': 'off',
114+
'sort-imports': ['error', { ignoreDeclarationSort: true }],
115+
'unused-imports/no-unused-imports': 'error',
116+
'unused-imports/no-unused-vars': [
117+
'error',
118+
{
119+
vars: 'all',
120+
varsIgnorePattern: '^_',
121+
args: 'after-used',
122+
argsIgnorePattern: '^_',
123+
},
124+
],
125+
'valid-typeof': ['error', { requireStringLiterals: false }],
126+
'@stylistic/comma-dangle': [
127+
'error',
128+
{
129+
arrays: 'always-multiline',
130+
objects: 'always-multiline',
131+
imports: 'always-multiline',
132+
exports: 'always-multiline',
133+
functions: 'always-multiline',
134+
enums: 'always-multiline',
135+
generics: 'always-multiline',
136+
tuples: 'always-multiline',
137+
},
138+
],
139+
'@stylistic/function-call-argument-newline': ['error', 'consistent'],
140+
'@stylistic/indent': 'off',
141+
'@stylistic/max-len': [
142+
'error',
143+
{
144+
code: 120,
145+
ignoreComments: true,
146+
ignoreUrls: true,
147+
ignoreStrings: true,
148+
ignoreTemplateLiterals: true,
149+
ignoreRegExpLiterals: true,
150+
},
151+
],
152+
'@stylistic/padding-line-between-statements': [
153+
'error',
154+
{ blankLine: 'always', prev: '*', next: 'return' },
155+
],
156+
'@typescript-eslint/method-signature-style': ['error', 'method'],
157+
'@typescript-eslint/no-confusing-void-expression': 'error',
158+
'@typescript-eslint/no-explicit-any': 'off',
159+
'@typescript-eslint/no-namespace': ['error', { allowDeclarations: true }],
160+
'@typescript-eslint/no-shadow': 'error',
161+
'@typescript-eslint/no-var-requires': 'off',
162+
'@typescript-eslint/no-unused-vars': 'off',
163+
'@typescript-eslint/no-use-before-define': [
164+
'error',
165+
{ functions: false, variables: false, classes: false },
166+
],
167+
'@typescript-eslint/no-useless-constructor': 'error',
168+
'@typescript-eslint/prefer-destructuring': [
169+
'error',
170+
{ object: true, array: false },
171+
],
172+
'@typescript-eslint/space-before-function-paren': [
173+
'error',
174+
{ anonymous: 'never', named: 'never', asyncArrow: 'always' },
175+
],
176+
'jsdoc/no-undefined-types': 1,
177+
},
178+
settings: {
179+
'import/parsers': {
180+
'@typescript-eslint/parser': ['.ts', '.tsx'],
181+
},
182+
'import/resolver': {
183+
typescript: {
184+
alwaysTryTypes: true,
185+
project: ['packages/*/tsconfig.json', 'tsconfig.json'],
186+
},
187+
},
188+
'import/ignore': ['react-native'],
189+
},
190+
};

.prettierignore

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ docs
55
package.json
66
yarn.lock
77
package-lock.json
8-
.eslintrc.js
98
www
109
.stencil
1110
PULL_REQUEST_TEMPLATE.md

.vscode/extensions.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
// List of extensions which should be recommended for users of this workspace.
55
"recommendations": [
66
"esbenp.prettier-vscode",
7-
"tombonnike.vscode-status-bar-format-toggle"
7+
"tombonnike.vscode-status-bar-format-toggle",
8+
"dbaeumer.vscode-eslint"
89
],
910
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
1011
"unwantedRecommendations": []

.vscode/settings.json

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
{
2-
"[typescript]": {
3-
"editor.defaultFormatter": "esbenp.prettier-vscode"
4-
},
5-
"editor.defaultFormatter": "esbenp.prettier-vscode",
62
"editor.detectIndentation": false,
7-
"editor.formatOnSave": true,
83
"editor.insertSpaces": false,
94
"editor.tabSize": 4,
105
"prettier.requireConfig": true,
11-
"typescript.tsdk": "node_modules/typescript/lib"
6+
"typescript.tsdk": "node_modules/typescript/lib",
7+
"formattingToggle.affects": [
8+
"editor.codeActionsOnSave.source.fixAll.eslint"
9+
]
1210
}

package.json

+14
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"clean:size": "lerna run clean:size --parallel",
2424
"format": "lerna run format",
2525
"lint": "lerna run lint",
26+
"lint:fix": "lerna run lint:fix",
2627
"lint:license": "license-check-and-add add -f license_config.json",
2728
"link-all": "yarn unlink-all && lerna exec --no-bail --parallel yarn link",
2829
"unlink-all": "lerna exec --no-bail --parallel -- yarn unlink; exit 0",
@@ -84,11 +85,24 @@
8485
"@size-limit/file": "^8.1.0",
8586
"@size-limit/webpack": "^8.1.0",
8687
"@size-limit/webpack-why": "^8.1.0",
88+
"@stylistic/eslint-plugin": "^1.5.4",
8789
"@types/jest": "^29.5.8",
8890
"@types/lodash": "4.14.182",
8991
"@types/node": "^8.9.5",
9092
"@types/puppeteer": "1.3.0",
93+
"@typescript-eslint/eslint-plugin": "^6.20.0",
94+
"@typescript-eslint/parser": "^6.20.0",
9195
"babel-loader": "^8.3.0",
96+
"eslint": "^8.56.0",
97+
"eslint-config-prettier": "^9.1.0",
98+
"eslint-config-standard": "^17.1.0",
99+
"eslint-import-resolver-typescript": "^3.6.1",
100+
"eslint-plugin-import": "^2.29.1",
101+
"eslint-plugin-jsdoc": "^48.0.4",
102+
"eslint-plugin-n": "^16.6.2",
103+
"eslint-plugin-prettier": "^5.1.3",
104+
"eslint-plugin-promise": "^6.1.1",
105+
"eslint-plugin-unused-imports": "^3.0.0",
92106
"glob": "^10.3.10",
93107
"jest": "^29.7.0",
94108
"jest-environment-jsdom": "^29.7.0",

prettier.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** @type {import('prettier').Config} */
22
module.exports = {
3-
trailingComma: 'es5',
3+
trailingComma: 'all',
4+
printWidth: 80,
45
singleQuote: true,
56
useTabs: true,
67
arrowParens: 'avoid',

0 commit comments

Comments
 (0)