]> git.proxmox.com Git - pve-eslint.git/blobdiff - src/app.js
adapt some rules
[pve-eslint.git] / src / app.js
index 9ef2b95bacf7384fc48a7bff8c310aa9e65387ac..569b9cfee6a4df8e49b898f65cf8908760112232 100644 (file)
@@ -8,7 +8,10 @@ const program = require('commander');
 program
     .usage('[options] [<file(s) ...>]')
     .option('-c, --config <configfile>', 'uses <configfile> for eslint config instead.')
-    .option('-f, --fix', 'if set, fixes will be applied.');
+    .option('-e, --extend <configfile>', 'uses <configfile> ontop of default eslint config.')
+    .option('-f, --fix', 'if set, fixes will be applied.')
+    .option('--output-config', 'if set, only output the config as JSON and exit.')
+    ;
 
 program.on('--help', function() {
     console.log('');
@@ -18,11 +21,16 @@ program.on('--help', function() {
     console.log('');
 });
 
-if (process.argv.length <= 2) {
-    program.help();
+program.parse(process.argv);
+
+if (program.config && program.extend) {
+    console.error('Cannot use both, --config and --extend, at the same time!');
+    process.exit(1);
 }
 
-program.parse(process.argv);
+if (program.args.length < 1 && !program.outputConfig) {
+    program.help();
+}
 
 let paths = program.args;
 
@@ -203,7 +211,13 @@ const defaultConfig = {
        "no-whitespace-before-property": "warn",
        "object-curly-newline": "warn",
        "object-curly-spacing": ["warn", "always"],
-       "operator-linebreak": ["warn", "after", { overrides: { "?": "after" } }],
+       "operator-linebreak": ["warn", "after", {
+           "overrides": {
+               "?": "before",
+               ":": "before",
+               "+": "ignore",
+           },
+       }],
        "padded-blocks": ["warn", "never"], // not sure ...
        "quote-props": ["warn", "as-needed", { keywords: true, unnecessary: false }], // does nothing, maybe deactivate unnecessary
        "semi": "warn",
@@ -217,7 +231,7 @@ const defaultConfig = {
        "unicode-bom": "warn",
        "arrow-body-style": "warn",
        "arrow-spacing": "warn",
-       "no-confusing-arrow": "warn",
+       // "no-confusing-arrow": "warn", // can be useful to do and isn't really confusing
        "prefer-numeric-literals": "warn",
        "template-curly-spacing": "warn",
      },
@@ -235,6 +249,15 @@ if (program.config) {
     config = {
        "extends": pathExpand(program.config),
     };
+} else if (program.extend) {
+    config.extends = pathExpand(program.extend);
+    console.log(`Extend with path: ${config.extends}`);
+}
+
+if (program.outputConfig) {
+    let cfg = JSON.stringify(config, null, 2);
+    console.log(cfg);
+    process.exit(0);
 }
 
 const cli = new eslint.CLIEngine({