Skip to content

Commit 46ef15b

Browse files
sidoshigaearon
authored andcommitted
Add custom eslint formatter (facebook#2138)
* Add custom eslint formatter * Add formatter docs * Update formatter docs * Slightly tweak it * Update README.md
1 parent d87cd35 commit 46ef15b

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

config/webpack.config.dev.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
1717
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
1818
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
1919
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
20+
const eslintFormatter = require('react-dev-utils/eslintFormatter');
2021
const getClientEnvironment = require('./env');
2122
const paths = require('./paths');
2223

@@ -120,16 +121,16 @@ module.exports = {
120121
enforce: 'pre',
121122
use: [
122123
{
123-
// @remove-on-eject-begin
124-
// Point ESLint to our predefined config.
125124
options: {
125+
formatter: eslintFormatter,
126+
// @remove-on-eject-begin
126127
baseConfig: {
127128
extends: ['react-app'],
128129
},
129130
ignore: false,
130131
useEslintrc: false,
132+
// @remove-on-eject-end
131133
},
132-
// @remove-on-eject-end
133134
loader: 'eslint-loader',
134135
},
135136
],

config/webpack.config.prod.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
1717
const ExtractTextPlugin = require('extract-text-webpack-plugin');
1818
const ManifestPlugin = require('webpack-manifest-plugin');
1919
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
20+
const eslintFormatter = require('react-dev-utils/eslintFormatter');
2021
const paths = require('./paths');
2122
const getClientEnvironment = require('./env');
2223

@@ -117,17 +118,18 @@ module.exports = {
117118
enforce: 'pre',
118119
use: [
119120
{
120-
// @remove-on-eject-begin
121-
// Point ESLint to our predefined config.
122121
options: {
122+
formatter: eslintFormatter,
123+
// @remove-on-eject-begin
123124
// TODO: consider separate config for production,
124125
// e.g. to enable no-console and no-debugger only in production.
125126
baseConfig: {
126127
extends: ['react-app'],
127128
},
129+
ignore: false,
128130
useEslintrc: false,
131+
// @remove-on-eject-end
129132
},
130-
// @remove-on-eject-end
131133
loader: 'eslint-loader',
132134
},
133135
],

scripts/utils/createWebpackCompiler.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,17 @@ module.exports = function createWebpackCompiler(config, onReadyCallback) {
100100
console.log(message);
101101
console.log();
102102
});
103+
103104
// Teach some ESLint tricks.
104-
console.log('You may use special comments to disable some warnings.');
105105
console.log(
106-
'Use ' +
107-
chalk.yellow('// eslint-disable-next-line') +
108-
' to ignore the next line.'
106+
'Search the ' +
107+
chalk.dim('keywords') +
108+
' from the right column to learn more.'
109109
);
110110
console.log(
111-
'Use ' +
112-
chalk.yellow('/* eslint-disable */') +
113-
' to ignore all warnings in a file.'
111+
'To ignore, add ' +
112+
chalk.yellow('// eslint-disable-next-line') +
113+
' to the line before.'
114114
);
115115
}
116116
});

0 commit comments

Comments
 (0)