]>
git.proxmox.com Git - pve-eslint.git/blob - src/app.js
8a89f9aaead9bb177d68d2c5385b7436c05df97c
4 const path
= require('path');
5 const color
= require('colors');
6 const program
= require('commander');
9 .usage('[options] [<file(s) ...>]')
10 .option('-c, --config <configfile>', 'uses <configfile> for eslint config instead.')
11 .option('-e, --extend <configfile>', 'uses <configfile> ontop of default eslint config.')
12 .option('-f, --fix', 'if set, fixes will be applied.')
13 .option('--output-config', 'if set, only output the config as JSON and exit.')
16 program
.on('--help', function() {
18 console
.log(' Description:');
20 console
.log(' lints javascript files');
24 program
.parse(process
.argv
);
26 if (program
.config
&& program
.extend
) {
27 console
.error('Cannot use both, --config and --extend, at the same time!');
31 if (program
.args
.length
< 1 && !program
.outputConfig
) {
35 let paths
= program
.args
;
38 paths
= [process
.cwd()];
41 const defaultConfig
= {
59 PVE_vnc_console_event
: "writable",
66 // from eslint:recommend, with tweaks for our source
67 "constructor-super": "error",
68 "for-direction": "error",
69 "getter-return": "error",
70 "no-async-promise-executor": "error",
71 "no-case-declarations": "error",
72 "no-class-assign": "error",
73 "no-compare-neg-zero": "error",
74 "no-cond-assign": "error",
75 "no-const-assign": "error",
76 "no-constant-condition": "error",
77 "no-control-regex": "error",
78 "no-debugger": "error",
79 "no-delete-var": "error",
80 "no-dupe-args": "error",
81 "no-dupe-class-members": "error",
82 "no-dupe-else-if": "error",
83 "no-dupe-keys": "error",
84 "no-duplicate-case": "error",
86 "no-empty-character-class": "error",
87 "no-empty-pattern": "error",
88 "no-ex-assign": "error",
89 "no-extra-boolean-cast": "error",
90 "no-extra-semi": "error",
91 "no-fallthrough": "error",
92 "no-func-assign": "error",
93 "no-global-assign": "error",
94 "no-import-assign": "error",
95 "no-inner-declarations": "error",
96 "no-invalid-regexp": "error",
97 "no-irregular-whitespace": "error",
98 "no-misleading-character-class": "error",
99 "no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
100 "no-new-symbol": "error",
101 "no-obj-calls": "error",
103 "no-prototype-builtins": "error",
104 "no-redeclare": "error",
105 "no-regex-spaces": "error",
106 "no-self-assign": "error",
107 "no-setter-return": "error",
108 "no-shadow-restricted-names": "error",
109 "no-sparse-arrays": "error",
110 "no-this-before-super": "error",
112 "no-unexpected-multiline": "error",
113 "no-unreachable": "error",
114 "no-unsafe-finally": "error",
115 "no-unsafe-negation": "error",
116 "no-unused-labels": "error",
117 "no-unused-vars": ["error", { vars
: "all", args
: "none", varsIgnorePattern
: "^(me|_.*)$" }],
118 "no-useless-catch": "error",
119 "no-useless-escape": "error",
121 "require-yield": "error",
122 "use-isnan": "error",
123 "valid-typeof": "error",
125 // selection of best practices
126 "accessor-pairs": "error",
127 "array-callback-return": "error",
128 "block-scoped-var": "error",
129 "consistent-return": "error",
130 "curly": ["error", "multi-line"],
131 "dot-location": ["error", "property"],
132 "dot-notation": "error",
134 "grouped-accessor-pairs": "error",
135 "guard-for-in": "error",
137 "no-await-in-loop": "error",
138 "no-caller": "error",
139 "no-constructor-return": "error",
140 "no-div-regex": "error",
141 "no-else-return": "error",
142 "no-empty-function": "error",
143 "no-eq-null": "error",
145 "no-extend-native": "error",
146 "no-extra-bind": "error",
147 "no-extra-label": "error",
148 "no-extra-parens": "error",
149 "no-floating-decimal": "error",
150 "no-implicit-coercion": ["error", { allow
: ["!!"] }],
151 "no-implicit-globals": "error",
152 "no-implied-eval": "error",
153 "no-invalid-this": "error",
154 "no-lone-blocks": "error",
155 "no-loop-func": "error",
156 "no-multi-spaces": "error",
157 "no-multi-str": "error",
159 "no-new-func": "error",
160 "no-new-wrappers": "error",
161 "no-octal-escape": "error",
163 "no-return-assign": "error",
164 "no-return-await": "error",
165 "no-script-url": "error",
166 "no-self-compare": "error",
167 "no-sequences": "error",
168 "no-template-curly-in-string": "error",
169 "no-unmodified-loop-condition": "error",
170 "no-unused-expressions": "error",
171 "no-useless-call": "error",
172 "no-useless-concat": "error",
173 "no-useless-return": "error",
175 "prefer-regex-literals": "error",
177 "require-atomic-updates": "error",
178 "wrap-iife": "error",
182 "no-label-var": "error",
183 "no-shadow": "error",
184 "no-undef-init": "error",
185 "no-use-before-define": "error",
187 // stylistic issues, only warn, most can be auto-fixed
188 // those are quite opinionated...
189 "array-bracket-spacing": ["warn", "never"],
190 "brace-style": ["warn", "1tbs", { allowSingleLine
: true }],
191 "comma-dangle": ["warn", "always-multiline"], // maybe only-multiline?
192 "comma-spacing": "warn",
193 "comma-style": "warn",
194 "computed-property-spacing": "warn",
195 "consistent-this": ["warn", "me"],
197 "func-call-spacing": "warn",
198 "func-name-matching": "warn",
199 "func-style": "warn",
200 "key-spacing": "warn",
201 "keyword-spacing": "warn",
202 "linebreak-style": "warn",
203 "max-len": ["warn", { code
: 110, tabWidth
: 8, ignoreComments
: true, ignoreStrings
: true, ignoreRegExpLiterals
: true }],
204 "no-array-constructor": "warn",
205 "no-lonely-if": "warn",
206 "no-mixed-operators": "warn",
207 "no-multiple-empty-lines": "warn",
208 "no-trailing-spaces": "warn",
209 "no-underscore-dangle": ["warn", { allowAfterThis
: true }],
210 "no-unneeded-ternary": "warn",
211 "no-whitespace-before-property": "warn",
212 "object-curly-newline": "warn",
213 "object-curly-spacing": ["warn", "always"],
214 "operator-linebreak": ["warn", "after", {
221 "padded-blocks": ["warn", "never"], // not sure ...
222 "quote-props": ["warn", "as-needed", { keywords
: true, unnecessary
: false }], // does nothing, maybe deactivate unnecessary
224 "semi-spacing": "warn",
225 // "semi-style": "warn", // could be useful, but for ?: we often want to allow the ; on the next line
226 "space-before-blocks": "warn",
227 "space-before-function-paren": ["warn", "never"],
228 "space-in-parens": "warn",
229 "space-unary-ops": "warn",
230 "switch-colon-spacing": "warn",
231 "unicode-bom": "warn",
232 "arrow-body-style": "warn",
233 "arrow-spacing": "warn",
234 // "no-confusing-arrow": "warn", // can be useful to do and isn't really confusing
235 "prefer-numeric-literals": "warn",
236 "template-curly-spacing": "warn",
240 let pathExpand
= (p
) => {
241 if (p
.match(/^[^/]/)) {
242 p
= process
.cwd() + "/" + p
;
247 let config
= defaultConfig
;
248 if (program
.config
) {
250 "extends": pathExpand(program
.config
),
252 } else if (program
.extend
) {
253 config
.extends = pathExpand(program
.extend
);
254 console
.log(`Extend with path: ${config.extends}`);
257 if (program
.outputConfig
) {
258 let cfg
= JSON
.stringify(config
, null, 2);
263 const cli
= new eslint
.CLIEngine({
269 const report
= cli
.executeOnFiles(paths
);
275 console
.log('------------------------------------------------------------');
276 report
.results
.forEach(function(result
) {
277 let filename
= path
.relative(process
.cwd(), result
.filePath
);
278 let msgs
= result
.messages
;
280 if (!!program
.fix
&& result
.output
) {
283 if (msgs
.length
<= 0) {
284 files_ok
.push(filename
);
287 console
.error(`[./${color.bold(filename)}]:`);
288 msgs
.forEach(function(e
) {
289 if (max_sev
< e
.severity
) {
290 max_sev
= e
.severity
;
292 let msg
= `: line ${color.bold(e.line)} col ${color.bold(e.column)}: ${e.ruleId}`;
293 if (e
.severity
=== 1) {
294 msg
= color
.yellow("WARN" + msg
);
295 } else if (e
.severity
=== 2) {
296 msg
= color
.red("ERR " + msg
);
304 msg
+= ` - ${e.message}`;
306 if (!program
.fix
&& e
.fix
) {
312 console
.error(e
.suggestion
);
317 files_warn
.push(filename
);
318 } else if (max_sev
=== 2) {
319 files_err
.push(filename
);
322 console
.log('------------------------------------------------------------');
325 if (report
.results
.length
> 1) {
326 console
.log(`${color.bold(files_ok.length + files_err.length)} files:`);
327 if (files_err
.length
> 0) {
328 console
.log(color
.red(` ${color.bold(files_err.length)} files have Errors`));
330 if (files_warn
.length
> 0) {
331 console
.log(color
.yellow(` ${color.bold(files_warn.length)} files have Warnings`));
333 if (files_ok
.length
> 0) {
334 console
.log(color
.green(` ${color.bold(files_ok.length)} files are OK`));
336 } else if (files_ok
.length
> 0) {
337 console
.log(color
.green(`${files_ok[0]} OK`));
339 console
.log('------------------------------------------------------------');
343 console
.log(`Writing ${color.bold(fixes)} fixed files...`);
344 eslint
.CLIEngine
.outputFixes(report
);
347 console
.log("No fixable Errors/Warnings found.");
349 } else if (fixes
> 0) {
350 console
.log(`${color.bold(fixes)} issues marked with (*) could be auto-fixed using '--fix'.`);
353 process
.exit(exitcode
);