Use eslint in build pipeline

This commit is contained in:
dominik-zeglen 2019-12-02 16:26:31 +01:00
parent 421da92cb3
commit baf49a7ca5
5 changed files with 151 additions and 48 deletions

View file

@ -1,18 +1,13 @@
{ {
"env": { "env": {
"browser": true "browser": true,
"node": true
}, },
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"parserOptions": { "parserOptions": {
"project": "tsconfig.json",
"sourceType": "module" "sourceType": "module"
}, },
"plugins": [ "plugins": ["@typescript-eslint", "import"],
"@typescript-eslint",
"@typescript-eslint/tslint",
"import",
"prefer-arrow"
],
"rules": { "rules": {
"@typescript-eslint/adjacent-overload-signatures": "error", "@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": [ "@typescript-eslint/array-type": [
@ -149,7 +144,6 @@
"no-var": "error", "no-var": "error",
"object-shorthand": "error", "object-shorthand": "error",
"one-var": ["error", "never"], "one-var": ["error", "never"],
"prefer-arrow/prefer-arrow-functions": "off",
"prefer-const": "error", "prefer-const": "error",
"prefer-object-spread": "error", "prefer-object-spread": "error",
"quote-props": "off", "quote-props": "off",
@ -158,18 +152,18 @@
"space-before-function-paren": "off", "space-before-function-paren": "off",
"spaced-comment": "error", "spaced-comment": "error",
"use-isnan": "error", "use-isnan": "error",
"valid-typeof": "off", "valid-typeof": "off"
"@typescript-eslint/tslint/config": [ // "@typescript-eslint/tslint/config": [
"error", // "error",
{ // {
"rules": { // "rules": {
"jsdoc-format": [true, "check-multiline-start"], // "jsdoc-format": [true, "check-multiline-start"],
"no-reference-import": true, // "no-reference-import": true,
"object-literal-sort-keys": true, // "object-literal-sort-keys": true,
"prefer-conditional-expression": true // "prefer-conditional-expression": true
} // }
} // }
] // ]
}, },
"ignorePatterns": ["node_modules/", "**/types/**/*"] "ignorePatterns": ["node_modules/", "**/types/**/*"]
} }

113
package-lock.json generated
View file

@ -10851,17 +10851,120 @@
"dev": true "dev": true
}, },
"fork-ts-checker-webpack-plugin": { "fork-ts-checker-webpack-plugin": {
"version": "0.5.2", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-0.5.2.tgz", "resolved": "https://registry.npmjs.org/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-3.1.1.tgz",
"integrity": "sha512-a5IG+xXyKnpruI0CP/anyRLAoxWtp3lzdG6flxicANnoSzz64b12dJ7ASAVRrI2OaWwZR2JyBaMHFQqInhWhIw==", "integrity": "sha512-DuVkPNrM12jR41KM2e+N+styka0EgLkTnXmNcXdgOM37vtGeY+oCBK/Jx0hzSeEU6memFCtWb4htrHPMDfwwUQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"babel-code-frame": "^6.22.0", "babel-code-frame": "^6.22.0",
"chalk": "^2.4.1", "chalk": "^2.4.1",
"chokidar": "^2.0.4", "chokidar": "^3.3.0",
"micromatch": "^3.1.10", "micromatch": "^3.1.10",
"minimatch": "^3.0.4", "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": { "form-data": {

View file

@ -123,7 +123,7 @@
"eslint-plugin-import": "^2.18.2", "eslint-plugin-import": "^2.18.2",
"eslint-plugin-prefer-arrow": "^1.1.6", "eslint-plugin-prefer-arrow": "^1.1.6",
"file-loader": "^1.1.11", "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", "html-webpack-plugin": "^3.2.0",
"husky": "^3.0.8", "husky": "^3.0.8",
"jest": "^24.8.0", "jest": "^24.8.0",

View file

@ -1,4 +1,4 @@
/* eslint-disable */ /* eslint-disable @typescript-eslint/no-var-requires */
const path = require("path"); const path = require("path");
const CheckerPlugin = require("fork-ts-checker-webpack-plugin"); const CheckerPlugin = require("fork-ts-checker-webpack-plugin");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin"); const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
@ -7,13 +7,13 @@ const resolve = resolvePath => path.resolve(__dirname, resolvePath);
module.exports = ({ config }) => { module.exports = ({ config }) => {
config.module.rules.push({ config.module.rules.push({
test: /\.(jsx?|tsx?)$/,
exclude: /node_modules/, exclude: /node_modules/,
loader: "babel-loader", loader: "babel-loader",
options: { options: {
configFile: resolve("../../babel.config.js"), configFile: resolve("../../babel.config.js"),
envName: "storybook" envName: "storybook"
} },
test: /\.(jsx?|tsx?)$/
}); });
config.optimization.removeAvailableModules = false; config.optimization.removeAvailableModules = false;
config.optimization.removeEmptyChunks = false; config.optimization.removeEmptyChunks = false;
@ -24,6 +24,10 @@ module.exports = ({ config }) => {
configFile: "./tsconfig.json" configFile: "./tsconfig.json"
}) })
]; ];
config.plugins.push(new CheckerPlugin()); config.plugins.push(
new CheckerPlugin({
eslint: true
})
);
return config; return config;
}; };

View file

@ -1,8 +1,10 @@
const CheckerPlugin = require("fork-ts-checker-webpack-plugin"); /* eslint-disable @typescript-eslint/no-var-requires */
const path = require("path"); const path = require("path");
const CheckerPlugin = require("fork-ts-checker-webpack-plugin");
const webpack = require("webpack"); const webpack = require("webpack");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin"); const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin"); const HtmlWebpackPlugin = require("html-webpack-plugin");
require("dotenv").config(); require("dotenv").config();
const resolve = path.resolve.bind(path, __dirname); const resolve = path.resolve.bind(path, __dirname);
@ -12,12 +14,12 @@ const pathsPlugin = new TsconfigPathsPlugin({
}); });
const checkerPlugin = new CheckerPlugin({ const checkerPlugin = new CheckerPlugin({
reportFiles: ["src/**/*.{ts,tsx}"], eslint: true,
tslint: true reportFiles: ["src/**/*.{ts,tsx}"]
}); });
const htmlWebpackPlugin = new HtmlWebpackPlugin({ const htmlWebpackPlugin = new HtmlWebpackPlugin({
hash: true,
filename: "index.html", filename: "index.html",
hash: true,
template: "./src/index.html" template: "./src/index.html"
}); });
const environmentPlugin = new webpack.EnvironmentPlugin([ const environmentPlugin = new webpack.EnvironmentPlugin([
@ -36,17 +38,17 @@ module.exports = (env, argv) => {
if (!devMode) { if (!devMode) {
const publicPath = process.env.STATIC_URL || "/"; const publicPath = process.env.STATIC_URL || "/";
output = { output = {
path: resolve(dashboardBuildPath),
filename: "[name].[chunkhash].js",
chunkFilename: "[name].[chunkhash].js", chunkFilename: "[name].[chunkhash].js",
filename: "[name].[chunkhash].js",
path: resolve(dashboardBuildPath),
publicPath publicPath
}; };
fileLoaderPath = "file-loader?name=[name].[hash].[ext]"; fileLoaderPath = "file-loader?name=[name].[hash].[ext]";
} else { } else {
output = { output = {
path: resolve(dashboardBuildPath),
filename: "[name].js",
chunkFilename: "[name].js", chunkFilename: "[name].js",
filename: "[name].js",
path: resolve(dashboardBuildPath),
publicPath: "/" publicPath: "/"
}; };
fileLoaderPath = "file-loader?name=[name].[ext]"; fileLoaderPath = "file-loader?name=[name].[ext]";
@ -54,35 +56,35 @@ module.exports = (env, argv) => {
return { return {
devServer: { devServer: {
contentBase: path.join(__dirname, dashboardBuildPath),
compress: true, compress: true,
contentBase: path.join(__dirname, dashboardBuildPath),
historyApiFallback: true, historyApiFallback: true,
hot: true, hot: true,
port: 9000 port: 9000
}, },
devtool: "sourceMap",
entry: { entry: {
dashboard: "./src/index.tsx" dashboard: "./src/index.tsx"
}, },
output,
module: { module: {
rules: [ rules: [
{ {
test: /\.(jsx?|tsx?)$/,
exclude: /node_modules/, exclude: /node_modules/,
loader: "babel-loader", loader: "babel-loader",
options: { options: {
configFile: resolve("./babel.config.js") configFile: resolve("./babel.config.js")
} },
test: /\.(jsx?|tsx?)$/
}, },
{ {
test: /\.(eot|otf|png|svg|jpg|ttf|woff|woff2)(\?v=[0-9.]+)?$/,
loader: fileLoaderPath,
include: [ include: [
resolve("node_modules"), resolve("node_modules"),
resolve("assets/fonts"), resolve("assets/fonts"),
resolve("assets/images"), resolve("assets/images"),
resolve("assets/favicons") 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, removeEmptyChunks: false,
splitChunks: false splitChunks: false
}, },
output,
plugins: [checkerPlugin, environmentPlugin, htmlWebpackPlugin], plugins: [checkerPlugin, environmentPlugin, htmlWebpackPlugin],
resolve: { resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"], extensions: [".js", ".jsx", ".ts", ".tsx"],
plugins: [pathsPlugin] plugins: [pathsPlugin]
}, }
devtool: "sourceMap"
}; };
}; };