|
| 1 | +const fs = require('fs') |
1 | 2 | const globby = require('globby')
|
2 | 3 |
|
3 | 4 | const renamedArrayArgs = {
|
@@ -31,26 +32,34 @@ module.exports = function lint (args = {}, api) {
|
31 | 32 | cwd
|
32 | 33 | }, argsConfig)
|
33 | 34 |
|
34 |
| - const engine = new CLIEngine(config) |
| 35 | + if (!fs.existsSync(api.resolve('.eslintignore'))) { |
| 36 | + // .eslintrc.js files (ignored by default) |
| 37 | + // However, we need to lint & fix them so as to make the default generated project's |
| 38 | + // code style consistent with user's selected eslint config. |
| 39 | + // Though, if users provided their own `.eslintignore` file, we don't want to |
| 40 | + // add our own customized ignore pattern here (in eslint, ignorePattern is |
| 41 | + // an addition to eslintignore, i.e. it can't be overriden by user), |
| 42 | + // following the principle of least astonishment. |
| 43 | + config.ignorePattern = [ |
| 44 | + '!.*.js', |
| 45 | + '!{src,tests}/**/.*.js' |
| 46 | + ] |
| 47 | + } |
35 | 48 |
|
36 |
| - // .eslintrc.js files (ignored by default) |
37 |
| - const dotFiles = [ |
38 |
| - '.*.js', |
39 |
| - '{src,tests}/**/.*.js' |
40 |
| - ].filter(pattern => globby.sync(path.join(cwd, pattern)).length) |
| 49 | + const engine = new CLIEngine(config) |
41 | 50 |
|
42 | 51 | const defaultFilesToLint = [
|
43 | 52 | 'src',
|
44 | 53 | 'tests',
|
45 | 54 | // root config files
|
46 |
| - '*.js' |
| 55 | + '*.js', |
| 56 | + '.*.js' |
47 | 57 | ]
|
48 | 58 | .filter(pattern =>
|
49 | 59 | globby
|
50 | 60 | .sync(path.join(cwd, pattern))
|
51 | 61 | .some(p => !engine.isPathIgnored(p))
|
52 | 62 | )
|
53 |
| - .concat(dotFiles) |
54 | 63 |
|
55 | 64 | const files = args._ && args._.length
|
56 | 65 | ? args._
|
|
0 commit comments