-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
160 lines (147 loc) · 5.18 KB
/
Copy pathindex.js
File metadata and controls
160 lines (147 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
const { addRegexRuleName } = require('eslint-plugin-regex');
// addRegexRuleName throws if the rule name is already registered. ESLint can
// load this config more than once per lint run (via import-fresh, which
// bypasses the Node.js require cache — notably when an overrides[] block in
// a child config uses `extends`, as typescript/index.js does). Swallow the
// redefine error so repeated loads remain a no-op.
try {
addRegexRuleName('invalid-product-id-parsing');
} catch (err) {
if (!/already defined/i.test(err && err.message)) throw err;
}
const ATTEMPT_AT_PARSING_PRODUCT_IDS = /('mixmax-product-ids'\)|productIds?)[\.\[]|for.* (of|in) productIds?|(match|test)\s*\(\s*(productIds?|.*'mixmax-product-ids')/i;
module.exports = {
env: {
es6: true,
},
extends: 'eslint:recommended',
plugins: ['import', 'regex'],
rules: {
'arrow-parens': ['error', 'always'],
'prefer-const': ['error'],
// Disallow var-type variable declarations. This, combined with the prefer-const rule, will let
// eslint automatically replace vars with either lets or consts as appropriate.
'no-var': 'error',
'object-shorthand': [
'error',
'always',
{
// This prefers the shorthand object method syntax over arrow functions when they use an
// explicit return statement. This normalizes methods in most cases, provided they don't
// interact with `this` and aren't expression-derived arrow functions.
avoidExplicitReturnArrows: true,
},
],
'space-before-function-paren': [
'error',
{
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
},
],
'jsx-quotes': ['error', 'prefer-single'],
'no-mixed-operators': ['error', { groups: [['&&', '||']] }],
indent: [
'error',
2,
{
SwitchCase: 1,
},
],
'linebreak-style': ['error', 'unix'],
semi: ['error', 'always'],
'no-use-before-define': ['error', 'nofunc'],
'no-unused-vars': [
'error',
{
// Per https://github.com/eslint/eslint/issues/1494#issuecomment-232890308.
argsIgnorePattern: 'next',
},
],
quotes: [
'error',
'single',
{
// Let people use strings like "don't worry about single quotes".
avoidEscape: true,
},
],
// Enforce our whitespace styles around keywords.
'keyword-spacing': [
'error',
{
overrides: {
function: {
after: false,
},
},
},
],
'no-return-await': ['error'],
// Console logs should be mostly nonexistent, and places like app.js should just have a
// /* eslint-disable no-console */
// comment at the top, or be specified as an override in the appropriate .eslintrc file.
'no-console': ['error'],
/**
* TODO: Investigate and fix these (harmless) errors (there are several in `app` throughout our
* client-side code, eg in `StringUtils`).
*
* Note that Express routes play by their own escaping rules and can cause ESLint to fail so
* we'll need to explicitly ignore the rule in our Express route declarations that use regexps.
*/
'no-useless-escape': 'off',
// Error when we use parseInt incorrectly or without the radix parameter.
radix: ['error', 'always'],
// Only allow throwing Error objects.
'no-throw-literal': ['error'],
// Require consistent return values (either always or never specifying values) so we don't
// rely on implicit returns when return booleans or undefined.
'consistent-return': ['error', { treatUndefinedAsUnspecified: true }],
'eol-last': ['error', 'always'],
'import/first': 'warn',
'import/no-useless-path-segments': 'warn',
'import/order': [
'warn',
{
alphabetize: { order: 'asc', caseInsensitive: true },
'newlines-between': 'always',
pathGroups: [
{ pattern: '@mixmaxhq/**', group: 'external', position: 'after' },
{ pattern: '{,~}/utils/**', group: 'internal', position: 'before' },
{ pattern: '{,~}/**', group: 'internal' },
],
pathGroupsExcludedImportTypes: ['builtin'],
groups: ['builtin', 'external', 'internal', ['parent', 'sibling'], 'index'],
},
],
// Also sort the named imports _within_ an import statement.
'sort-imports': ['warn', { ignoreDeclarationSort: true }],
// Ensure that we use curly braces for multi-line statements and that if one statement uses
// curly braces, they all do.
curly: ['warn', 'multi-line', 'consistent'],
'regex/invalid-product-id-parsing': [
'error',
[
{
message:
'Please do not parse or look into the product ids; product-based decisions must be' +
' based on feature checks. See README in `monorepo-billing/libs/features-sdk`.',
regex: ATTEMPT_AT_PARSING_PRODUCT_IDS.toString().split('/')[1],
flags: ATTEMPT_AT_PARSING_PRODUCT_IDS.toString().split('/')[2],
files: {
inspect: '\\.(js|tsx?)$',
},
},
],
],
},
overrides: [
{
files: ['flow-typed/**'],
rules: {
'no-use-before-define': 'off',
},
},
],
};