]>
git.proxmox.com Git - pve-eslint.git/blob - src/app.js
289a012fb1dac4e0d4eb4c5d466612afb2810f16
4 const color
= require('colors');
5 const program
= require('commander');
8 .usage('[options] [<file(s) ...>]')
9 .option('-c, --config <configfile>', 'uses <configfile> for eslint config instead.')
10 .option('-f, --fix', 'if set, fixes will be applied.');
12 program
.on('--help', function() {
14 console
.log(' Description:');
16 console
.log(' lints javascript files');
20 if (process
.argv
.length
<= 2) {
24 program
.parse(process
.argv
);
26 let paths
= program
.args
;
29 paths
= [process
.cwd()];
32 const defaultConfig
= {
50 PVE_vnc_console_event
: "writable",
57 // from eslint:recommend, with tweaks for our source
58 "constructor-super": "error",
59 "for-direction": "error",
60 "getter-return": "error",
61 "no-async-promise-executor": "error",
62 "no-case-declarations": "error",
63 "no-class-assign": "error",
64 "no-compare-neg-zero": "error",
65 "no-cond-assign": "error",
66 "no-const-assign": "error",
67 "no-constant-condition": "error",
68 "no-control-regex": "error",
69 "no-debugger": "error",
70 "no-delete-var": "error",
71 "no-dupe-args": "error",
72 "no-dupe-class-members": "error",
73 "no-dupe-else-if": "error",
74 "no-dupe-keys": "error",
75 "no-duplicate-case": "error",
77 "no-empty-character-class": "error",
78 "no-empty-pattern": "error",
79 "no-ex-assign": "error",
80 "no-extra-boolean-cast": "error",
81 "no-extra-semi": "error",
82 "no-fallthrough": "error",
83 "no-func-assign": "error",
84 "no-global-assign": "error",
85 "no-import-assign": "error",
86 "no-inner-declarations": "error",
87 "no-invalid-regexp": "error",
88 "no-irregular-whitespace": "error",
89 "no-misleading-character-class": "error",
90 "no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
91 "no-new-symbol": "error",
92 "no-obj-calls": "error",
94 "no-prototype-builtins": "error",
95 "no-redeclare": "error",
96 "no-regex-spaces": "error",
97 "no-self-assign": "error",
98 "no-setter-return": "error",
99 "no-shadow-restricted-names": "error",
100 "no-sparse-arrays": "error",
101 "no-this-before-super": "error",
103 "no-unexpected-multiline": "error",
104 "no-unreachable": "error",
105 "no-unsafe-finally": "error",
106 "no-unsafe-negation": "error",
107 "no-unused-labels": "error",
108 "no-unused-vars": ["error", { vars
: "all", args
: "none" } ],
109 "no-useless-catch": "error",
110 "no-useless-escape": "error",
112 "require-yield": "error",
113 "use-isnan": "error",
114 "valid-typeof": "error",
116 // selection of best practices
117 "accessor-pairs": "error",
118 "array-callback-return": "error",
119 "block-scoped-var": "error",
120 "consistent-return": "error",
121 "curly": ["error", "multi-line"],
122 "dot-location": ["error", "property"],
123 "dot-notation": "error",
125 "grouped-accessor-pairs": "error",
126 "guard-for-in": "error",
128 "no-await-in-loop": "error",
129 "no-caller": "error",
130 "no-constructor-return": "error",
131 "no-div-regex": "error",
132 "no-else-return": "error",
133 "no-empty-function": "error",
134 "no-eq-null": "error",
136 "no-extend-native": "error",
137 "no-extra-bind": "error",
138 "no-extra-label": "error",
139 "no-extra-parens": "error",
140 "no-floating-decimal": "error",
141 "no-implicit-coercion": ["error", { allow
: ["!!"] }],
142 "no-implicit-globals": "error",
143 "no-implied-eval": "error",
144 "no-invalid-this": "error",
145 "no-lone-blocks": "error",
146 "no-loop-func": "error",
147 "no-multi-spaces": "error",
148 "no-multi-str": "error",
150 "no-new-func": "error",
151 "no-new-wrappers": "error",
152 "no-octal-escape": "error",
154 "no-return-assign": "error",
155 "no-return-await": "error",
156 "no-script-url": "error",
157 "no-self-compare": "error",
158 "no-sequences": "error",
159 "no-template-curly-in-string": "error",
160 "no-unmodified-loop-condition": "error",
161 "no-unused-expressions": "error",
162 "no-useless-call": "error",
163 "no-useless-concat": "error",
164 "no-useless-return": "error",
166 "prefer-regex-literals": "error",
168 "require-atomic-updates": "error",
169 "wrap-iife": "error",
173 "no-label-var": "error",
174 "no-shadow": "error",
175 "no-undef-init": "error",
176 "no-use-before-define": "error",
178 // stylistic issues, only warn, most can be auto-fixed
179 // those are quite opinionated...
180 "array-bracket-spacing": [ "warn", "never" ],
181 "brace-style": [ "warn", "1tbs", { allowSingleLine
: true }],
182 "comma-dangle": [ "warn", "always-multiline" ], // maybe only-multiline?
183 "comma-spacing": "warn",
184 "comma-style": "warn",
185 "computed-property-spacing": "warn",
186 "consistent-this": [ "warn", "me" ],
188 "func-call-spacing": "warn",
189 "func-name-matching": "warn",
190 "func-style": "warn",
191 "key-spacing": "warn",
192 "keyword-spacing": "warn",
193 "linebreak-style": "warn",
194 "max-len": [ "warn", { code
: 110, tabWidth
: 8, ignoreComments
: true, ignoreStrings
: true, ignoreRegExpLiterals
: true }],
195 "no-array-constructor": "warn",
196 "no-lonely-if": "warn",
197 "no-mixed-operators": "warn",
198 "no-multiple-empty-lines": "warn",
199 "no-trailing-spaces": "warn",
200 "no-underscore-dangle": [ "warn", { allowAfterThis
: true, }],
201 "no-unneeded-ternary": "warn",
202 "no-whitespace-before-property": "warn",
203 "object-curly-newline": "warn",
204 "object-curly-spacing": [ "warn", "always" ],
205 "operator-linebreak" : [ "warn", "after", { overrides
: { "?": "after" }}],
206 "padded-blocks": ["warn", "never"], // not sure ...
207 "quote-props": [ "warn", "as-needed", { keywords
: true, unnecessary
: false }], // does nothing, maybe deactivate unnecessary
209 "semi-spacing": "warn",
210 "semi-style": "warn",
211 "space-before-blocks": "warn",
212 "space-before-function-paren": ["warn", "never"],
213 "space-in-parens": "warn",
214 "space-unary-ops": "warn",
215 "switch-colon-spacing": "warn",
216 "unicode-bom": "warn",
217 "arrow-body-style": "warn",
218 "arrow-spacing": "warn",
219 "no-confusing-arrow": "warn",
220 "prefer-numeric-literals": "warn",
221 "template-curly-spacing": "warn",
225 let config
= defaultConfig
;
226 if (program
.config
) {
227 let path
= program
.config
;
228 if (program
.config
.match(/^[^/]/)) {
229 path
= process
.cwd() + "/" + path
;
236 const cli
= new eslint
.CLIEngine({
242 const report
= cli
.executeOnFiles(paths
);
248 console
.log('------------------------------------------------------------');
249 report
.results
.forEach(function(result
) {
250 let filename
= result
.filePath
;
251 let msgs
= result
.messages
;
253 if (!!program
.fix
&& result
.output
) {
256 if (msgs
.length
> 0) {
257 console
.error('[' + color
.bold(filename
) + ']:');
258 msgs
.forEach(function(e
) {
259 let msg
= 'at line ' + color
.bold(e
.line
) + ' column ' +
260 color
.bold(e
.column
) + ': ' + e
.ruleId
;
261 if (e
.severity
=== 1) {
262 console
.error(color
.yellow("Warning " + msg
));
266 } else if (e
.severity
=== 2) {
267 console
.error(color
.red("Error " + msg
));
275 console
.error("Info " + msg
);
278 console
.error(e
.message
);
281 console
.error(e
.suggestion
);
283 if (!program
.fix
&& e
.fix
) {
285 console
.error("Could be auto-fixed");
290 files_warn
.push(filename
);
291 } else if (max_sev
=== 2) {
292 files_err
.push(filename
);
295 files_ok
.push(filename
);
299 console
.log('------------------------------------------------------------');
302 if (report
.results
.length
> 1) {
303 console
.log((`${color.bold(files_ok.length + files_err.length)} files:`));
304 if (files_err
.length
> 0) {
305 console
.log(color
.red(`${color.bold(files_err.length)} files have Errors`));
307 if (files_warn
.length
> 0) {
308 console
.log(color
.yellow(`${color.bold(files_warn.length)} files have Warnings`));
310 if (files_ok
.length
> 0) {
311 console
.log(color
.green(`${color.bold(files_ok.length)} files are OK`));
313 console
.log('------------------------------------------------------------');
314 } else if (files_ok
.length
> 0) {
315 console
.log(color
.green(`${files_ok[0]} OK`));
316 console
.log('------------------------------------------------------------');
321 console
.log(`Writing ${color.bold(fixes)} fixed files...`);
322 eslint
.CLIEngine
.outputFixes(report
);
325 console
.log("No fixable Errors/Warnings found.");
328 console
.log(`${color.bold(fixes)} Errors/Warnings could be auto-fixed.`);
331 process
.exit(exitcode
);