UNPKG

5.53 kBJavaScriptView Raw
1"use strict";
2
3var _checkSetup = require("@sharyn/check-setup");
4
5// flow-disable-next-line
6var config = {
7 extends: [],
8 plugins: [],
9 env: {
10 browser: true
11 },
12 globals: {},
13 rules: {
14 'no-unused-expressions': 0,
15 'no-underscore-dangle': 0,
16 'func-names': 0,
17 'no-unexpected-multiline': 2,
18 'prefer-destructuring': [2, {
19 VariableDeclarator: {
20 object: true,
21 array: true
22 },
23 AssignmentExpression: {
24 object: false,
25 array: false
26 }
27 }],
28 semi: [2, 'never']
29 },
30 settings: {}
31};
32
33if ((0, _checkSetup.hasPackage)('eslint-config-airbnb') && (0, _checkSetup.hasPackage)('eslint-config-airbnb-base')) {
34 throw Error('Your package.json should either have eslint-config-airbnb or eslint-config-airbnb-base as a dependency but not both');
35}
36
37if ((0, _checkSetup.hasPackage)('eslint-config-airbnb')) {
38 config.extends.push('airbnb');
39
40 if (!(0, _checkSetup.hasPackage)('eslint-plugin-import')) {
41 throw Error('eslint-config-airbnb requires having eslint-plugin-import installed');
42 }
43
44 if (!(0, _checkSetup.hasPackage)('eslint-plugin-react')) {
45 throw Error('eslint-config-airbnb requires having eslint-plugin-react installed');
46 }
47
48 if (!(0, _checkSetup.hasPackage)('eslint-plugin-jsx-a11y')) {
49 throw Error('eslint-config-airbnb requires having eslint-plugin-jsx-a11y installed');
50 }
51}
52
53if ((0, _checkSetup.hasPackage)('eslint-config-airbnb-base')) {
54 config.extends.push('airbnb-base');
55
56 if (!(0, _checkSetup.hasPackage)('eslint-plugin-import')) {
57 throw Error('eslint-config-airbnb-base requires having eslint-plugin-import installed');
58 }
59}
60
61if ((0, _checkSetup.hasPackage)('jest-puppeteer')) {
62 config.globals.page = true;
63 config.globals.browser = true;
64 config.globals.jestPuppeteer = true;
65}
66
67if ((0, _checkSetup.hasPackage)('jest')) {
68 config.env.jest = true;
69}
70
71if ((0, _checkSetup.hasPackage)('eslint-plugin-flowtype')) {
72 config.extends.push('plugin:flowtype/recommended');
73 config.plugins.push('flowtype');
74
75 if (!(0, _checkSetup.hasPackage)('flow-bin')) {
76 throw Error('eslint-plugin-flowtype requires having flow-bin installed');
77 }
78
79 if (!(0, _checkSetup.hasPackage)('babel-eslint')) {
80 throw Error('eslint-plugin-flowtype requires having babel-eslint installed');
81 }
82}
83
84if ((0, _checkSetup.hasPackage)('eslint-plugin-prettier')) {
85 config.plugins.push('prettier');
86 config.rules['prettier/prettier'] = 2;
87
88 if (!(0, _checkSetup.hasPackage)('prettier')) {
89 throw Error('eslint-plugin-prettier requires having prettier installed');
90 }
91}
92
93if ((0, _checkSetup.hasPackage)('eslint-config-prettier')) {
94 config.extends.push('prettier');
95
96 if ((0, _checkSetup.hasPackage)('react')) {
97 config.extends.push('prettier/react');
98 }
99
100 if ((0, _checkSetup.hasPackage)('flow-bin')) {
101 config.extends.push('prettier/flowtype');
102 }
103
104 if (!(0, _checkSetup.hasPackage)('prettier')) {
105 throw Error('eslint-config-prettier requires having prettier installed');
106 }
107}
108
109if ((0, _checkSetup.hasPackage)('eslint-plugin-react')) {
110 config.rules['react/require-default-props'] = 0;
111 config.rules['react/jsx-filename-extension'] = [2, {
112 extensions: ['.js']
113 }];
114
115 if (!(0, _checkSetup.hasPackage)('eslint-config-airbnb')) {
116 config.extends.push('plugin:react/recommended');
117 }
118
119 if (!(0, _checkSetup.hasPackage)('react')) {
120 throw Error('eslint-plugin-react requires having react installed');
121 }
122}
123
124if ((0, _checkSetup.hasPackage)('eslint-plugin-import')) {
125 config.rules['import/prefer-default-export'] = 0;
126}
127
128if ((0, _checkSetup.hasPackage)('eslint-import-resolver-babel-module')) {
129 config.settings['import/resolver'] = {
130 'babel-module': {}
131 };
132
133 if (!(0, _checkSetup.hasPackage)('@babel/core')) {
134 throw Error('eslint-import-resolver-babel-module requires having @babel/core installed');
135 }
136
137 if (!(0, _checkSetup.hasPackage)('babel-plugin-module-resolver')) {
138 throw Error('eslint-import-resolver-babel-module requires having babel-plugin-module-resolver installed');
139 }
140
141 if (!(0, _checkSetup.hasPackage)('eslint-plugin-import')) {
142 throw Error('eslint-import-resolver-babel-module requires having eslint-plugin-import installed');
143 }
144}
145
146if ((0, _checkSetup.hasPackage)('@babel/plugin-proposal-do-expressions') && !(0, _checkSetup.hasPackage)('babel-eslint')) {
147 throw Error('@babel/plugin-proposal-do-expressions requires having babel-eslint installed');
148}
149
150if ((0, _checkSetup.hasPackage)('@babel/plugin-proposal-nullish-coalescing-operator') && !(0, _checkSetup.hasPackage)('babel-eslint')) {
151 throw Error('@babel/plugin-proposal-nullish-coalescing-operator requires having babel-eslint installed');
152}
153
154if ((0, _checkSetup.hasPackage)('@babel/plugin-proposal-optional-chaining') && !(0, _checkSetup.hasPackage)('babel-eslint')) {
155 throw Error('@babel/plugin-proposal-optional-chaining requires having babel-eslint installed');
156}
157
158if ((0, _checkSetup.hasPackage)('@babel/plugin-proposal-pipeline-operator') && !(0, _checkSetup.hasPackage)('babel-eslint')) {
159 throw Error('@babel/plugin-proposal-pipeline-operator requires having babel-eslint installed');
160}
161
162if ((0, _checkSetup.hasPackage)('flow-bin') && !(0, _checkSetup.hasPackage)('babel-eslint')) {
163 throw Error('flow-bin requires having babel-eslint installed');
164}
165
166if ((0, _checkSetup.hasPackage)('babel-eslint')) {
167 config.parser = 'babel-eslint';
168}
169
170if ((0, _checkSetup.hasPackage)('react')) {
171 config.parserOptions = {
172 ecmaFeatures: {
173 jsx: true
174 }
175 };
176}
177
178module.exports = config;
\No newline at end of file