-
Notifications
You must be signed in to change notification settings - Fork 1
/
babel.js
89 lines (75 loc) · 2.84 KB
/
babel.js
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
// Move to own repo so can have `@babel/eslint-parser` and
// `@babel/eslint-plugin` as deps.
// Adapted from MIT-licensed: https://github.com/futagoza/eslint-config-futagozaryuu/blob/master/packages/%40futagoza/eslint-config-core/stylistic-issues.js
// Types: https://github.com/babel/babel/issues/16221
import babelParser from '@babel/eslint-parser';
import babelEslintPlugin from '@babel/eslint-plugin';
/**
* Allows passing in a whole config to wrap.
* @param {import('eslint').Linter.Config} config
* @returns {import('eslint').Linter.Config}
*/
export default function babelConfig (config) {
return {
name: 'ash-nazg/babel',
languageOptions: {
parser: babelParser,
parserOptions: {
...config.languageOptions?.parserOptions,
requireConfigFile: false
}
},
plugins: {
...config.plugins,
babelEslintPlugin
},
rules: {
...config.rules,
// `@babel/eslint-plugin` provides better support for the following rules
'new-cap': 'off',
'no-invalid-this': 'off',
'no-unused-expressions': 'off',
'@stylistic/object-curly-spacing': 'off',
'object-curly-spacing': 'off',
'@stylistic/semi': 'off',
semi: 'off',
/**
* Require constructor names to begin with a capital letter.
*
* @see {@link https://eslint.org/docs/rules/new-cap}
* @see {@link https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin#rules}
*/
'@babel/new-cap': config?.rules?.['new-cap'] || 'off',
/**
* Disallow `this` keywords outside of classes or class-like objects.
*
* @see {@link https://eslint.org/docs/rules/no-invalid-this}
* @see {@link https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin#rules}
*/
'@babel/no-invalid-this': config?.rules?.['no-invalid-this'] || 'off',
/**
* Disallow unused expressions.
*
* @see {@link https://eslint.org/docs/rules/no-unused-expressions}
* @see {@link https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin#rules}
*/
'@babel/no-unused-expressions':
config?.rules?.['no-unused-expressions'] || 'off',
/**
* Enforce consistent spacing inside braces (🔧 ).
*
* @see {@link https://eslint.org/docs/rules/object-curly-spacing}
* @see {@link https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin#rules}
*/
'@babel/object-curly-spacing':
config?.rules?.['object-curly-spacing'] || 'off',
/**
* Require or disallow semicolons instead of ASI (🔧).
*
* @see {@link https://eslint.org/docs/rules/semi}
* @see {@link https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin#rules}
*/
'@babel/semi': config?.rules?.semi || 'off'
}
};
}