Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

Replace TSLint with eslint-config-react-app-ts #388

Closed
wants to merge 13 commits into from
Closed
10 changes: 4 additions & 6 deletions config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const getPublicUrl = appPackageJson =>
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
function getServedPath(appPackageJson) {
const publicUrl = getPublicUrl(appPackageJson);
const servedUrl = envPublicUrl ||
(publicUrl ? url.parse(publicUrl).pathname : '/');
const servedUrl =
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
return ensureSlash(servedUrl, true);
}

Expand All @@ -60,7 +60,6 @@ module.exports = {
appNodeModules: resolveApp('node_modules'),
appTsConfig: resolveApp('tsconfig.json'),
appTsProdConfig: resolveApp('tsconfig.prod.json'),
appTsLint: resolveApp('tslint.json'),
publicUrl: getPublicUrl(resolveApp('package.json')),
servedPath: getServedPath(resolveApp('package.json')),
};
Expand All @@ -84,7 +83,6 @@ module.exports = {
appTsConfig: resolveApp('tsconfig.json'),
appTsProdConfig: resolveApp('tsconfig.prod.json'),
appTsTestConfig: resolveApp('tsconfig.test.json'),
appTsLint: resolveApp('tslint.json'),
publicUrl: getPublicUrl(resolveApp('package.json')),
servedPath: getServedPath(resolveApp('package.json')),
// These properties only exist before ejecting:
Expand All @@ -94,7 +92,8 @@ module.exports = {

const ownPackageJson = require('../package.json');
const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
const reactScriptsLinked = fs.existsSync(reactScriptsPath) &&
const reactScriptsLinked =
fs.existsSync(reactScriptsPath) &&
fs.lstatSync(reactScriptsPath).isSymbolicLink();

// config before publish: we're in ./packages/react-scripts/config/
Expand All @@ -116,7 +115,6 @@ if (
appNodeModules: resolveOwn('node_modules'),
appTsConfig: resolveOwn('template/tsconfig.json'),
appTsProdConfig: resolveOwn('template/tsconfig.prod.json'),
appTsLint: resolveOwn('template/tslint.json'),
appTsTestConfig: resolveOwn('template/tsconfig.test.json'),
publicUrl: getPublicUrl(resolveOwn('package.json')),
servedPath: getServedPath(resolveOwn('package.json')),
Expand Down
39 changes: 35 additions & 4 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
const eslintFormatter = require('react-dev-utils/eslintFormatter');
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const getClientEnvironment = require('./env');
Expand Down Expand Up @@ -134,10 +135,41 @@ module.exports = {
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
// { parser: { requireEnsure: false } },

// First, run the linter.
// It's important to do this before Babel processes the JS.
{
test: /\.(js|jsx|mjs)$/,
loader: require.resolve('source-map-loader'),
test: /\.(js|jsx|mjs|ts|tsx)$/,
enforce: 'pre',
use: [
require.resolve('source-map-loader'),
{
options: {
formatter: eslintFormatter,
eslintPath: require.resolve('eslint'),
baseConfig: {
extends: [require.resolve('eslint-config-react-app')],
parser: 'typescript-eslint-parser',
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
'no-array-constructor': 'off',
'no-multi-str': 'off',
'no-restricted-globals': 'off',
'no-undef': 'off',
'no-unused-vars': 'off',
},
},
],
},
// @remove-on-eject-begin
ignore: false,
useEslintrc: false,
// @remove-on-eject-end
},
loader: require.resolve('eslint-loader'),
},
],
include: paths.appSrc,
},
{
Expand Down Expand Up @@ -275,12 +307,11 @@ module.exports = {
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
// You can remove this if you don't use Moment.js:
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// Perform type checking and linting in a separate process to speed up compilation
// Perform type checking in a separate process to speed up compilation
new ForkTsCheckerWebpackPlugin({
async: false,
watch: paths.appSrc,
tsconfig: paths.appTsConfig,
tslint: paths.appTsLint,
}),
],
// Some libraries import Node modules but don't use them in the browser.
Expand Down
42 changes: 38 additions & 4 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
const eslintFormatter = require('react-dev-utils/eslintFormatter');
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const paths = require('./paths');
Expand Down Expand Up @@ -140,10 +141,44 @@ module.exports = {
// TODO: Disable require.ensure as it's not a standard language feature.
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
// { parser: { requireEnsure: false } },

// First, run the linter.
// It's important to do this before Babel processes the JS.
{
test: /\.(js|jsx|mjs)$/,
loader: require.resolve('source-map-loader'),
test: /\.(js|jsx|mjs|ts|tsx)$/,
enforce: 'pre',
use: [
require.resolve('source-map-loader'),
{
options: {
formatter: eslintFormatter,
eslintPath: require.resolve('eslint'),
// TODO: consider separate config for production,
// e.g. to enable no-console and no-debugger only in production.
baseConfig: {
extends: [require.resolve('eslint-config-react-app')],
parser: 'typescript-eslint-parser',
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
'no-array-constructor': 'off',
'no-multi-str': 'off',
'no-restricted-globals': 'off',
'no-undef': 'off',
'no-unused-vars': 'off',
},
},
],
},
// @remove-on-eject-begin
ignore: false,
useEslintrc: false,
// @remove-on-eject-end
},
loader: require.resolve('eslint-loader'),
},
],
include: paths.appSrc,
},
{
Expand Down Expand Up @@ -382,11 +417,10 @@ module.exports = {
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
// You can remove this if you don't use Moment.js:
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// Perform type checking and linting in a separate process to speed up compilation
// Perform type checking in a separate process to speed up compilation
new ForkTsCheckerWebpackPlugin({
async: false,
tsconfig: paths.appTsProdConfig,
tslint: paths.appTsLint,
}),
],
// Some libraries import Node modules but don't use them in the browser.
Expand Down
20 changes: 16 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@
"bugs": {
"url": "https://github.com/wmonk/create-react-app/issues"
},
"files": ["bin", "config", "scripts", "template", "utils"],
"files": [
"bin",
"config",
"scripts",
"template",
"utils"
],
"bin": {
"react-scripts-ts": "./bin/react-scripts-ts.js"
},
"dependencies": {
"autoprefixer": "8.5.0",
"babel-eslint": "7.2.3",
"babel-jest": "22.4.3",
"babel-loader": "8.0.0-beta.4",
"babel-preset-react-app": "^3.1.1",
Expand All @@ -24,6 +31,13 @@
"css-loader": "0.28.11",
"dotenv": "5.0.1",
"dotenv-expand": "4.2.0",
"eslint": "4.10.0",
"eslint-config-react-app": "^2.1.0",
"eslint-loader": "1.9.0",
"eslint-plugin-flowtype": "2.39.1",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-jsx-a11y": "5.1.1",
"eslint-plugin-react": "7.4.0",
"extract-text-webpack-plugin": "3.0.2",
"file-loader": "1.1.11",
"fork-ts-checker-webpack-plugin": "0.4.9",
Expand All @@ -43,9 +57,7 @@
"ts-jest": "22.0.1",
"ts-loader": "4.5.0",
"tsconfig-paths-webpack-plugin": "^2.0.0",
"tslint": "^5.7.0",
"tslint-config-prettier": "^1.10.0",
"tslint-react": "^3.2.0",
"typescript-eslint-parser": "^16.0.1",
"uglifyjs-webpack-plugin": "1.2.5",
"url-loader": "1.0.1",
"webpack": "4.8.3",
Expand Down
1 change: 0 additions & 1 deletion template/src/registerServiceWorker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// tslint:disable:no-console
// In production, we register a service worker to serve assets from local cache.

// This lets the app load faster on subsequent visits in production, and gives
Expand Down
10 changes: 0 additions & 10 deletions template/tslint.json

This file was deleted.