Skip to content

Commit 387a617

Browse files
committedOct 29, 2020
Add extensions and noDefaultExtensions options; Allow all options to be passed into lintText / lintFiles, or specified in the package.json
Allow all options to be passed into lintText / lintFiles, or specified in the package.json: - New: Add `extensions` option - New: Add `noDefaultExtensions` option - New: Allow `ignore` to be passed in to lintText / lintFiles - New: Allow `noDefaultIgnore` to be passed in to lintText / lintFiles
1 parent 6abd959 commit 387a617

File tree

2 files changed

+54
-16
lines changed

2 files changed

+54
-16
lines changed
 

‎README.md

+36-13
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ string of the package:
102102

103103
```json
104104
{
105-
"standard-engine": "semistandard"
105+
"standard-engine": "pocketlint"
106106
}
107107
```
108108

@@ -111,7 +111,7 @@ or an object with a `name` value of the package:
111111
```json
112112
{
113113
"standard-engine": {
114-
"name": "semistandard"
114+
"name": "pocketlint"
115115
}
116116
}
117117
```
@@ -128,6 +128,19 @@ projects `package.json` file.
128128

129129
## Engine Features
130130

131+
### Extensions
132+
133+
The extensions `.js`, `.jsx`, `.mjs`, and `.cjs` are linted by default. If you
134+
pass directory paths to the `standardEngine.lintFiles()` method,
135+
`standard-engine` checks the files in those directories that have the given
136+
extensions.
137+
138+
For example, when passing the `src/` directory and the `extensions` option is
139+
`['.js', '.jsx']`, `standard-engine` will lint `*.js` and `*.jsx` files in
140+
`src/`.
141+
142+
You can disable these default ignores by setting the `noDefaultExensions` option to `true`.
143+
131144
### Ignoring Files
132145

133146
The paths `node_modules/**`, `*.min.js`, `coverage/**`, hidden files/folders
@@ -152,14 +165,14 @@ Some files are ignored by default:
152165

153166
```js
154167
var DEFAULT_IGNORE = [
155-
'**/*.min.js',
156-
'coverage/**',
157-
'node_modules/**',
158-
'vendor/**'
168+
'*.min.js',
169+
'coverage/',
170+
'node_modules/',
171+
'vendor/'
159172
]
160173
```
161174

162-
You can disable these default ignores by setting `noDefaultIgnore` option to `true`.
175+
You can disable these default ignores by setting the `noDefaultIgnore` option to `true`.
163176

164177
### Hiding Warnings
165178

@@ -294,7 +307,7 @@ Modify and return `opts`, or return a new object with the options that are to be
294307

295308
The following options are provided in the `opts` object, and must be on the returned object:
296309

297-
- `ignore`: array of file globs to ignore
310+
- `ignore`: array of file patterns (in `.gitignore` format) to ignore
298311
- `cwd`: string, the current working directory
299312
- `fix`: boolean, whether to automatically fix problems
300313
- `eslintConfig`: object, the options passed to [ESLint's `CLIEngine`](http://eslint.org/docs/developer-guide/nodejs-api#cliengine)
@@ -308,14 +321,19 @@ be provided:
308321

309322
```js
310323
{
311-
cwd: '', // current working directory (default: process.cwd())
324+
// unique to lintText
312325
filename: '', // path of file containing the text being linted
326+
327+
// common to lintText and lintFiles
328+
cwd: '', // current working directory (default: process.cwd())
313329
fix: false, // automatically fix problems
330+
extensions: [], // file extensions to lint (has sane defaults)
314331
globals: [], // custom global variables to declare
315332
plugins: [], // custom eslint plugins
316333
envs: [], // custom eslint environment
317334
parser: '', // custom js parser (e.g. babel-eslint)
318-
usePackageJson: true // use options from nearest package.json?
335+
usePackageJson: true, // use options from nearest package.json?
336+
useGitIgnore: true // use file ignore patterns from .gitignore?
319337
}
320338
```
321339

@@ -356,20 +374,25 @@ Lint the provided `files` globs. An `opts` object may be provided:
356374

357375
```js
358376
{
377+
// unique to lintFiles
359378
ignore: [], // file globs to ignore (has sane defaults)
379+
380+
// common to lintText and lintFiles
360381
cwd: '', // current working directory (default: process.cwd())
361382
fix: false, // automatically fix problems
383+
extensions: [], // file extensions to lint (has sane defaults)
362384
globals: [], // custom global variables to declare
363385
plugins: [], // custom eslint plugins
364386
envs: [], // custom eslint environment
365387
parser: '', // custom js parser (e.g. babel-eslint)
366-
usePackageJson: true // use options from nearest package.json?
388+
usePackageJson: true, // use options from nearest package.json?
389+
useGitIgnore: true // use file ignore patterns from .gitignore?
367390
}
368391
```
369392

370393
Additional options may be loaded from a `package.json` if it's found for the current working directory. See below for further details.
371394

372-
Both `ignore` and `files` globs are resolved relative to the current working directory.
395+
Both `ignore` and `files` patterns are resolved relative to the current working directory.
373396

374397
The `callback` will be called with an `Error` and `results` object (same as above).
375398

@@ -381,7 +404,7 @@ This is the full set of options accepted by the above APIs. Not all options make
381404

382405
```js
383406
{
384-
ignore: [], // file globs to ignore (has sane defaults)
407+
ignore: [], // file patterns to ignore (has sane defaults)
385408
cwd: '', // current working directory (default: process.cwd())
386409
filename: '', // path of the file containing the text being linted (optional)
387410
fix: false, // automatically fix problems

‎index.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function Linter (opts) {
5050
globals: [],
5151
plugins: [],
5252
ignorePattern: [],
53-
extensions: DEFAULT_EXTENSIONS,
53+
extensions: [],
5454
useEslintrc: false
5555
}, opts.eslintConfig)
5656

@@ -137,6 +137,7 @@ Linter.prototype.parseOpts = function (opts) {
137137
cwd: self.cwd,
138138
fix: false,
139139
ignore: [],
140+
extensions: [],
140141
...opts
141142
}
142143

@@ -157,10 +158,19 @@ Linter.prototype.parseOpts = function (opts) {
157158

158159
if (!opts.usePackageJson) packageOpts = {}
159160

160-
if (!packageOpts.noDefaultIgnore) {
161+
addIgnore(packageOpts.ignore)
162+
addIgnore(opts.ignore)
163+
164+
if (!packageOpts.noDefaultIgnore && !opts.noDefaultIgnore) {
161165
addIgnore(DEFAULT_IGNORE)
162166
}
163-
addIgnore(packageOpts.ignore)
167+
168+
addExtensions(packageOpts.extensions)
169+
addExtensions(opts.extensions)
170+
171+
if (!packageOpts.noDefaultExtensions && !opts.noDefaultExtensions) {
172+
addExtensions(DEFAULT_EXTENSIONS)
173+
}
164174

165175
if (opts.useGitIgnore) {
166176
opts.gitIgnoreFile
@@ -199,6 +209,11 @@ Linter.prototype.parseOpts = function (opts) {
199209
opts = self.customParseOpts(opts, packageOpts, rootDir)
200210
}
201211

212+
function addExtensions (extensions) {
213+
if (!extensions) return
214+
opts.eslintConfig.extensions = opts.eslintConfig.extensions.concat(extensions)
215+
}
216+
202217
function addIgnore (ignore) {
203218
if (!ignore) return
204219
opts.eslintConfig.ignorePattern = opts.eslintConfig.ignorePattern.concat(ignore)

0 commit comments

Comments
 (0)
Please sign in to comment.