From baf49a7ca555335609310479e84b2f2fdcf75d6e Mon Sep 17 00:00:00 2001 From: dominik-zeglen Date: Mon, 2 Dec 2019 16:26:31 +0100 Subject: [PATCH] Use eslint in build pipeline --- .eslintrc.json | 36 +++++----- package-lock.json | 113 ++++++++++++++++++++++++++++++-- package.json | 2 +- src/storybook/webpack.config.js | 12 ++-- webpack.config.js | 36 +++++----- 5 files changed, 151 insertions(+), 48 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 9de8290eb..e60fbc1ed 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,18 +1,13 @@ { "env": { - "browser": true + "browser": true, + "node": true }, "parser": "@typescript-eslint/parser", "parserOptions": { - "project": "tsconfig.json", "sourceType": "module" }, - "plugins": [ - "@typescript-eslint", - "@typescript-eslint/tslint", - "import", - "prefer-arrow" - ], + "plugins": ["@typescript-eslint", "import"], "rules": { "@typescript-eslint/adjacent-overload-signatures": "error", "@typescript-eslint/array-type": [ @@ -149,7 +144,6 @@ "no-var": "error", "object-shorthand": "error", "one-var": ["error", "never"], - "prefer-arrow/prefer-arrow-functions": "off", "prefer-const": "error", "prefer-object-spread": "error", "quote-props": "off", @@ -158,18 +152,18 @@ "space-before-function-paren": "off", "spaced-comment": "error", "use-isnan": "error", - "valid-typeof": "off", - "@typescript-eslint/tslint/config": [ - "error", - { - "rules": { - "jsdoc-format": [true, "check-multiline-start"], - "no-reference-import": true, - "object-literal-sort-keys": true, - "prefer-conditional-expression": true - } - } - ] + "valid-typeof": "off" + // "@typescript-eslint/tslint/config": [ + // "error", + // { + // "rules": { + // "jsdoc-format": [true, "check-multiline-start"], + // "no-reference-import": true, + // "object-literal-sort-keys": true, + // "prefer-conditional-expression": true + // } + // } + // ] }, "ignorePatterns": ["node_modules/", "**/types/**/*"] } diff --git a/package-lock.json b/package-lock.json index a32a7bfa1..d97ec2009 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10851,17 +10851,120 @@ "dev": true }, "fork-ts-checker-webpack-plugin": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-0.5.2.tgz", - "integrity": "sha512-a5IG+xXyKnpruI0CP/anyRLAoxWtp3lzdG6flxicANnoSzz64b12dJ7ASAVRrI2OaWwZR2JyBaMHFQqInhWhIw==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-3.1.1.tgz", + "integrity": "sha512-DuVkPNrM12jR41KM2e+N+styka0EgLkTnXmNcXdgOM37vtGeY+oCBK/Jx0hzSeEU6memFCtWb4htrHPMDfwwUQ==", "dev": true, "requires": { "babel-code-frame": "^6.22.0", "chalk": "^2.4.1", - "chokidar": "^2.0.4", + "chokidar": "^3.3.0", "micromatch": "^3.1.10", "minimatch": "^3.0.4", - "tapable": "^1.0.0" + "semver": "^5.6.0", + "tapable": "^1.0.0", + "worker-rpc": "^0.1.0" + }, + "dependencies": { + "anymatch": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.1.tgz", + "integrity": "sha512-mM8522psRCqzV+6LhomX5wgp25YVibjh8Wj23I5RPkPppSVSjyKD2A2mBJmWGa+KN7f2D6LNh9jkBCeyLktzjg==", + "dev": true, + "requires": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + } + }, + "binary-extensions": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.0.0.tgz", + "integrity": "sha512-Phlt0plgpIIBOGTT/ehfFnbNlfsDEiqmzE2KRXoX1bLIlir4X/MR+zSyBEkL05ffWgnRSf/DXv+WrUAVr93/ow==", + "dev": true + }, + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "requires": { + "fill-range": "^7.0.1" + } + }, + "chokidar": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.3.0.tgz", + "integrity": "sha512-dGmKLDdT3Gdl7fBUe8XK+gAtGmzy5Fn0XkkWQuYxGIgWVPPse2CxFA5mtrlD0TOHaHjEUqkWNyP1XdHoJES/4A==", + "dev": true, + "requires": { + "anymatch": "~3.1.1", + "braces": "~3.0.2", + "fsevents": "~2.1.1", + "glob-parent": "~5.1.0", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.2.0" + } + }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "requires": { + "to-regex-range": "^5.0.1" + } + }, + "fsevents": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.2.tgz", + "integrity": "sha512-R4wDiBwZ0KzpgOWetKDug1FZcYhqYnUYKtfZYt4mD5SBz76q0KR4Q9o7GIPamsVPGmW3EYPPJ0dOOjvx32ldZA==", + "dev": true, + "optional": true + }, + "glob-parent": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.0.tgz", + "integrity": "sha512-qjtRgnIVmOfnKUE3NJAQEdk+lKrxfw8t5ke7SXtfMTHcjsBfOfWXCQfdb30zfDoZQ2IRSIiidmjtbHZPZ++Ihw==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + }, + "is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "requires": { + "binary-extensions": "^2.0.0" + } + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true + }, + "readdirp": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.2.0.tgz", + "integrity": "sha512-crk4Qu3pmXwgxdSgGhgA/eXiJAPQiX4GMOZZMXnqKxHX7TaoL+3gQVo/WeuAiogr07DpnfjIMpXXa+PAIvwPGQ==", + "dev": true, + "requires": { + "picomatch": "^2.0.4" + } + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "requires": { + "is-number": "^7.0.0" + } + } } }, "form-data": { diff --git a/package.json b/package.json index de4818bbd..a6b40e384 100644 --- a/package.json +++ b/package.json @@ -123,7 +123,7 @@ "eslint-plugin-import": "^2.18.2", "eslint-plugin-prefer-arrow": "^1.1.6", "file-loader": "^1.1.11", - "fork-ts-checker-webpack-plugin": "^0.5.2", + "fork-ts-checker-webpack-plugin": "^3.1.1", "html-webpack-plugin": "^3.2.0", "husky": "^3.0.8", "jest": "^24.8.0", diff --git a/src/storybook/webpack.config.js b/src/storybook/webpack.config.js index 9c94ff6cb..e74604815 100644 --- a/src/storybook/webpack.config.js +++ b/src/storybook/webpack.config.js @@ -1,4 +1,4 @@ -/* eslint-disable */ +/* eslint-disable @typescript-eslint/no-var-requires */ const path = require("path"); const CheckerPlugin = require("fork-ts-checker-webpack-plugin"); const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin"); @@ -7,13 +7,13 @@ const resolve = resolvePath => path.resolve(__dirname, resolvePath); module.exports = ({ config }) => { config.module.rules.push({ - test: /\.(jsx?|tsx?)$/, exclude: /node_modules/, loader: "babel-loader", options: { configFile: resolve("../../babel.config.js"), envName: "storybook" - } + }, + test: /\.(jsx?|tsx?)$/ }); config.optimization.removeAvailableModules = false; config.optimization.removeEmptyChunks = false; @@ -24,6 +24,10 @@ module.exports = ({ config }) => { configFile: "./tsconfig.json" }) ]; - config.plugins.push(new CheckerPlugin()); + config.plugins.push( + new CheckerPlugin({ + eslint: true + }) + ); return config; }; diff --git a/webpack.config.js b/webpack.config.js index d68988963..a61e7595c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,8 +1,10 @@ -const CheckerPlugin = require("fork-ts-checker-webpack-plugin"); +/* eslint-disable @typescript-eslint/no-var-requires */ const path = require("path"); +const CheckerPlugin = require("fork-ts-checker-webpack-plugin"); const webpack = require("webpack"); const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin"); const HtmlWebpackPlugin = require("html-webpack-plugin"); + require("dotenv").config(); const resolve = path.resolve.bind(path, __dirname); @@ -12,12 +14,12 @@ const pathsPlugin = new TsconfigPathsPlugin({ }); const checkerPlugin = new CheckerPlugin({ - reportFiles: ["src/**/*.{ts,tsx}"], - tslint: true + eslint: true, + reportFiles: ["src/**/*.{ts,tsx}"] }); const htmlWebpackPlugin = new HtmlWebpackPlugin({ - hash: true, filename: "index.html", + hash: true, template: "./src/index.html" }); const environmentPlugin = new webpack.EnvironmentPlugin([ @@ -36,17 +38,17 @@ module.exports = (env, argv) => { if (!devMode) { const publicPath = process.env.STATIC_URL || "/"; output = { - path: resolve(dashboardBuildPath), - filename: "[name].[chunkhash].js", chunkFilename: "[name].[chunkhash].js", + filename: "[name].[chunkhash].js", + path: resolve(dashboardBuildPath), publicPath }; fileLoaderPath = "file-loader?name=[name].[hash].[ext]"; } else { output = { - path: resolve(dashboardBuildPath), - filename: "[name].js", chunkFilename: "[name].js", + filename: "[name].js", + path: resolve(dashboardBuildPath), publicPath: "/" }; fileLoaderPath = "file-loader?name=[name].[ext]"; @@ -54,35 +56,35 @@ module.exports = (env, argv) => { return { devServer: { - contentBase: path.join(__dirname, dashboardBuildPath), compress: true, + contentBase: path.join(__dirname, dashboardBuildPath), historyApiFallback: true, hot: true, port: 9000 }, + devtool: "sourceMap", entry: { dashboard: "./src/index.tsx" }, - output, module: { rules: [ { - test: /\.(jsx?|tsx?)$/, exclude: /node_modules/, loader: "babel-loader", options: { configFile: resolve("./babel.config.js") - } + }, + test: /\.(jsx?|tsx?)$/ }, { - test: /\.(eot|otf|png|svg|jpg|ttf|woff|woff2)(\?v=[0-9.]+)?$/, - loader: fileLoaderPath, include: [ resolve("node_modules"), resolve("assets/fonts"), resolve("assets/images"), resolve("assets/favicons") - ] + ], + loader: fileLoaderPath, + test: /\.(eot|otf|png|svg|jpg|ttf|woff|woff2)(\?v=[0-9.]+)?$/ } ] }, @@ -91,11 +93,11 @@ module.exports = (env, argv) => { removeEmptyChunks: false, splitChunks: false }, + output, plugins: [checkerPlugin, environmentPlugin, htmlWebpackPlugin], resolve: { extensions: [".js", ".jsx", ".ts", ".tsx"], plugins: [pathsPlugin] - }, - devtool: "sourceMap" + } }; };