Procházet zdrojové kódy

HUE-8687 [frontend] Add eslint

To get the javascript in shape, we can add eslint to
the project, but we need to have a set of files we want to
target. I think it might be good to move the webpack
code to a separate folder and then we lint stuff as we move things there.

Added 'dev' target to package.json.  It runs webpack with watch mode
and -d to put webpack in debug mode so it generates sourcemaps.
jheyming před 6 roky
rodič
revize
50b77d807c
3 změnil soubory, kde provedl 82 přidání a 1 odebrání
  1. 69 0
      .eslintrc.js
  2. 4 0
      .prettierrc
  3. 9 1
      package.json

+ 69 - 0
.eslintrc.js

@@ -0,0 +1,69 @@
+
+const normalGlobals = [
+  'ko', 'jQuery', '$', '_', 'Promise'
+];
+const hueGlobals = [
+  // global_js_constants.mako
+  'IS_HUE_4', 'AUTOCOMPLETE_TIMEOUT','CSRF_TOKEN','HAS_MULTI_CLUSTER',
+  'DROPZONE_HOME_DIR', 'ENABLE_SQL_SYNTAX_CHECK', 'HAS_NAVIGATOR', 'HAS_OPTIMIZER', 'HAS_WORKLOAD_ANALYTICS',
+  'HUE_CONTAINER', 'IS_EMBEDDED', 'IS_K8S_ONLY', 'HUE_VERSION', 'IS_NEW_INDEXER_ENABLED',
+  'IS_S3_ENABLED', 'DOCUMENT_TYPES', 'LOGGED_USERNAME', 'USER_HOME_DIR', 'LOGGED_USERGROUPS', 'METASTORE_PARTITION_LIMIT',
+
+  // other misc, TODO
+  'huePubSub', 'ApiHelper', 'SqlUtils', 'ContextCatalog', 'DataCatalog'
+];
+
+const globals = normalGlobals.concat(hueGlobals).reduce((acc, key) => {
+  acc[key] = true;
+  return acc;
+}, {});
+
+
+module.exports = {
+  env: {
+    browser: true,
+    node: true,
+    es6: true
+  },
+  extends: [
+    'plugin:prettier/recommended'
+  ],
+  globals: globals,
+  parser: 'babel-eslint',
+  parserOptions: {
+    ecmaVersion: 2017,
+    sourceType: 'module',
+    ecmaFeatures: {
+    }
+  },
+  plugins: [],
+  rules: {
+    'new-cap': 0,
+    'no-console': 0,
+    'no-extra-boolean-cast': 0,
+    'no-invalid-this': 0,
+    'no-lonely-if': 2,
+    'no-throw-literal': 0,
+    'no-unused-vars': [
+      'error',
+      {
+        vars: 'all',
+        args: 'none',
+        ignoreRestSiblings: true,
+        varsIgnorePattern: '_[a-zA-Z0-9_]+'
+      }
+    ],
+    'no-useless-constructor': 2,
+    'no-var': 1,
+    'no-undef': 2,
+    'one-var': 0,
+    'prefer-arrow-callback': 2,
+    'prefer-const': ['warn', { destructuring: 'all' }],
+    'require-jsdoc': 0,
+    strict: 0,
+    'valid-jsdoc': 0,
+    curly: [2, 'all']
+  },
+  settings: {
+  }
+};

+ 4 - 0
.prettierrc

@@ -0,0 +1,4 @@
+{
+  "printWidth": 100,
+  "singleQuote": true
+}

+ 9 - 1
package.json

@@ -39,8 +39,12 @@
     "architect-build": "0.1.1",
     "@babel/preset-env": "7.3.1",
     "babel-cli": "6.26.0",
+    "babel-eslint": "10.0.1",
     "babel-jscs": "3.0.0-beta1",
     "babel-loader": "8.0.5",
+    "eslint": "5.12.1",
+    "eslint-config-prettier": "4.0.0",
+    "eslint-plugin-prettier": "3.0.1",
     "expose-loader": "0.7.5",
     "dryice": "0.4.11",
     "grunt": "1.0.3",
@@ -48,6 +52,7 @@
     "grunt-contrib-uglify": "4.0.0",
     "grunt-contrib-watch": "1.1.0",
     "load-grunt-tasks": "4.0.0",
+    "prettier": "1.16.1",
     "webpack": "4.29.0",
     "webpack-bundle-tracker": "0.4.2-beta",
     "webpack-cli": "^3.2.1",
@@ -57,7 +62,10 @@
     "devinstall": "npm cache clean && npm install && npm prune",
     "less": "./node_modules/.bin/grunt less",
     "watch": "./node_modules/.bin/grunt watch",
-    "webpack": "webpack --config webpack.config.js"
+    "webpack": "webpack --config webpack.config.js",
+    "dev": "webpack --watch -d",
+    "lint": "cd desktop/core/src/desktop/static/desktop/js/; eslint assist autocomplete document",
+    "lint-fix": "npm run lint -- --fix"
   },
   "files": []
 }