Skip to content

Commit 2d8377c

Browse files
darkobitsRomain Ricard
andauthored
chore: Migrate to ESLint. (signalstickers#222)
* chore: Migrate to ESLint. * Fix missing space after line Co-authored-by: Romain Ricard <[email protected]>
1 parent ca02446 commit 2d8377c

29 files changed

+13003
-5791
lines changed

.eslintrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
extends: [
3+
require.resolve('@darkobits/ts-unified/dist/config/eslint-react')
4+
],
5+
rules: {
6+
'no-console': 'off'
7+
}
8+
};

babel.config.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
module.exports = {
2+
extends: '@darkobits/ts-unified/dist/config/babel',
23
presets: [
3-
require.resolve('@babel/preset-env'),
4-
require.resolve('@babel/preset-typescript'),
5-
require.resolve('@babel/preset-react'),
64
require.resolve('linaria/babel')
75
],
86
plugins: [
9-
require.resolve('react-hot-loader/babel'),
10-
require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'),
11-
require.resolve('@babel/plugin-proposal-optional-chaining'),
12-
require.resolve('@babel/plugin-proposal-class-properties'),
13-
require.resolve('@babel/plugin-transform-runtime'),
14-
[require.resolve('babel-plugin-module-resolver'), {
15-
cwd: 'packagejson',
16-
root: ['./src'],
17-
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json']
18-
}]
19-
],
20-
comments: false
7+
'react-hot-loader/babel'
8+
]
219
};

config/jest.config.js

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
11
const path = require('path');
22

3-
4-
const PKG_ROOT = path.resolve(__dirname, '..');
5-
6-
7-
const EXTENSIONS = ['ts', 'tsx', 'js', 'jsx', 'node'];
8-
9-
const ALWAYS_IGNORE = [
10-
`${PKG_ROOT}/dist`,
11-
'/node_modules/'
12-
];
13-
14-
15-
module.exports = {
16-
rootDir: PKG_ROOT,
17-
testEnvironment: 'node',
18-
testRegex: '^.+\\.spec.*$',
19-
testPathIgnorePatterns: ALWAYS_IGNORE,
20-
coveragePathIgnorePatterns: ALWAYS_IGNORE,
21-
moduleFileExtensions: [...EXTENSIONS, 'json'],
22-
collectCoverageFrom: [
23-
`${PKG_ROOT}/src/**/*.{${EXTENSIONS.join(',')}}`,
24-
`${PKG_ROOT}/tests/**/*.{${EXTENSIONS.join(',')}}`,
25-
'!**/node_modules/**',
26-
],
3+
module.exports = require('@darkobits/ts-unified/dist/config/jest')({
4+
rootDir: path.resolve(__dirname, '..'),
275
clearMocks: true,
286
coverageThreshold: {
297
global: {
@@ -33,4 +11,4 @@ module.exports = {
3311
lines: 100
3412
}
3513
}
36-
};
14+
});

config/webpack.config.ts renamed to config/webpack.config.babel.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'path';
22

33
import FetchStickerDataPlugin from '@signalstickers/fetch-sticker-data-webpack-plugin';
4+
import {CleanWebpackPlugin} from 'clean-webpack-plugin';
45
import CopyWebpackPlugin from 'copy-webpack-plugin';
56
// @ts-ignore (No type definitions exist for this package.)
67
import FaviconsWebpackPlugin from 'favicons-webpack-plugin';
@@ -41,23 +42,20 @@ export default (env: string, argv: any): webpack.Configuration => {
4142

4243
// ----- Loaders -------------------------------------------------------------
4344

44-
// TSLint (Development only).
45-
if (argv.mode === 'development') {
46-
config.module.rules.push({
47-
test: /\.(ts|tsx)$/,
48-
exclude: /node_modules/,
49-
enforce: 'pre',
50-
use: [{
51-
loader: 'tslint-loader',
52-
options: {
53-
configFile: path.resolve(PKG_ROOT, 'tslint.json'),
54-
tsConfigFile: path.resolve(PKG_ROOT, 'tsconfig.json'),
55-
formatter: 'codeFrame',
56-
typeCheck: true
57-
}
58-
}]
59-
});
60-
}
45+
// ESLint
46+
config.module.rules.push({
47+
test: /\.(ts|tsx)$/,
48+
exclude: /node_modules/,
49+
enforce: 'pre',
50+
use: [{
51+
loader: 'eslint-loader',
52+
options: {
53+
emitErrors: true,
54+
emitWarning: true,
55+
failOnError: argv.mode === 'production'
56+
}
57+
}]
58+
});
6159

6260
// TypeScript & JavaScript files.
6361
config.module.rules.push({
@@ -164,27 +162,31 @@ export default (env: string, argv: any): webpack.Configuration => {
164162
config.plugins.push(new FriendlyErrorsWebpackPlugin());
165163

166164
config.plugins.push(new MiniCssExtractPlugin({
167-
filename: 'styles.css',
165+
filename: 'styles.css'
168166
}));
169167
}
170168

171169
if (argv.mode === 'production') {
172-
config.plugins.push(new CopyWebpackPlugin([{
173-
// When performing a production build, instruct Webpack to copy all files
174-
// in the 'static' directory into the build directory.
175-
from: path.resolve(PKG_ROOT, 'static'),
176-
to: path.resolve(PKG_ROOT, 'dist')
177-
}]));
170+
// Delete the build output directory before production builds.
171+
config.plugins.push(new CleanWebpackPlugin());
172+
173+
config.plugins.push(new CopyWebpackPlugin({
174+
patterns: [{
175+
// When performing a production build, instruct Webpack to copy all
176+
// files in the 'static' directory into the build directory.
177+
from: path.resolve(PKG_ROOT, 'static'),
178+
to: path.resolve(PKG_ROOT, 'dist')
179+
}]
180+
}));
178181

179182
config.plugins.push(new MiniCssExtractPlugin({
180-
filename: 'styles-[contenthash].css',
183+
filename: 'styles-[contenthash].css'
181184
}));
182185

183186
config.plugins.push(new webpack.LoaderOptionsPlugin({
184187
minimize: true
185188
}));
186189

187-
188190
config.plugins.push(new FaviconsWebpackPlugin({
189191
logo: path.resolve(PKG_ROOT, 'src', 'assets', 'favicon.png'),
190192
cache: true,
@@ -195,7 +197,7 @@ export default (env: string, argv: any): webpack.Configuration => {
195197
appDescription: '',
196198
version: '',
197199
developerName: '',
198-
developerURL: '',
200+
developerURL: ''
199201
}
200202
}));
201203
}

0 commit comments

Comments
 (0)