Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 1681ea6

Browse files
committed
Fix: do not extract/lint html by default
Fixes #1828 Closes gh-1871
1 parent 5de4417 commit 1681ea6

5 files changed

Lines changed: 73 additions & 62 deletions

File tree

OVERVIEW.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ Values: A single file extension or an Array of file extensions, beginning with a
299299

300300
Set list of glob patterns for files which embeded JavaScript should be checked.
301301

302-
Type: `Array` or `false`
302+
Type: `Array` or `Boolean`
303303

304304
Values: Array of file matching patterns
305305

@@ -311,9 +311,9 @@ JavaScript extracting from files that doesn't match to [fileExtensions](#fileExt
311311
"extract": ["*.htm", "*.html"]
312312
```
313313

314-
#### Default
314+
#### Value `true`
315315

316-
Default value is `["**/*.+(htm|html|xhtml)"]`. So JavaScript is extracted from files with `.htm`, `.html` or `.xhtml` extension.
316+
JavaScript is extracted from files with `.htm`, `.html` or `.xhtml` extension with value `true`.
317317

318318
### maxErrors
319319
Set the maximum number of errors to report (pass -1 or null to report all errors).

lib/config/configuration.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,6 @@ Configuration.prototype._processConfig = function(config) {
490490

491491
if (options.hasOwnProperty('extract')) {
492492
this._loadExtract(options.extract);
493-
494-
// Set default masks if there is no presets that could define their own
495-
} else if (!options.hasOwnProperty('preset')) {
496-
this._loadExtract(this._defaultExtractFileMasks);
497493
}
498494

499495
if (options.hasOwnProperty('fileExtensions')) {
@@ -745,12 +741,13 @@ Configuration.prototype._loadExcludedFiles = function(masks) {
745741
* @protected
746742
*/
747743
Configuration.prototype._loadExtract = function(masks) {
748-
if (masks === false) {
744+
if (masks === true) {
745+
masks = this._defaultExtractFileMasks;
746+
} else if (masks === false) {
749747
masks = [];
750748
}
751749

752-
assert(Array.isArray(masks), '`extract` option should be array of strings or false');
753-
750+
assert(Array.isArray(masks), '`extract` option should be array of strings');
754751
this._extractFileMasks = masks.slice();
755752
this._extractFileMatchers = this._extractFileMasks.map(function(fileMask) {
756753
return new minimatch.Minimatch(path.resolve(this._basePath, fileMask), {

test/specs/checker.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,7 @@ describe('checker', function() {
131131
});
132132

133133
describe('extract', function() {
134-
it('should extract from *.htm, *.html and *.xhtml by default', function() {
135-
return checker.checkPath('./test/data/extract').then(function(errors) {
136-
expect(errors.length).to.equal(3);
137-
expect(errors[0].getErrorList().length).to.equal(2);
138-
expect(errors[1].getErrorList().length).to.equal(2);
139-
expect(errors[2].getErrorList().length).to.equal(0);
140-
});
141-
});
142-
143-
it('should not extract js when set to false', function() {
144-
checker.configure({
145-
extract: false
146-
});
147-
134+
it('should not extract anything by default', function() {
148135
return checker.checkPath('./test/data/extract').then(function(errors) {
149136
expect(errors.length).to.equal(0);
150137
});
@@ -178,10 +165,6 @@ describe('checker', function() {
178165
});
179166

180167
it('extractFile should return null if file doesn\'t check', function() {
181-
checker.configure({
182-
extract: false
183-
});
184-
185168
return checker.extractFile('./test/data/extract/always.htm').then(function(errors) {
186169
expect(errors).to.equal(null);
187170
});

test/specs/config/configuration.js

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -325,25 +325,32 @@ describe('config/configuration', function() {
325325
});
326326

327327
describe('extract', function() {
328-
it('should be check html files by default', function() {
328+
it('should not check any files by default', function() {
329329
configuration.load({});
330-
expect(configuration.getExtractFileMasks()).to.deep.equal(['**/*.+(htm|html|xhtml)']);
330+
expect(configuration.getExtractFileMasks()).to.deep.equal([]);
331331
});
332332

333-
it('should set array of masks', function() {
333+
it('should check default files with value true', function() {
334334
configuration.load({
335-
extract: ['foo', 'bar']
335+
extract: true
336336
});
337-
expect(configuration.getExtractFileMasks()).to.deep.equal(['foo', 'bar']);
337+
expect(configuration.getExtractFileMasks()).to.deep.equal(['**/*.+(htm|html|xhtml)']);
338338
});
339339

340-
it('should set `never`', function() {
340+
it('should not check any files with value false', function() {
341341
configuration.load({
342342
extract: false
343343
});
344344
expect(configuration.getExtractFileMasks()).to.deep.equal([]);
345345
});
346346

347+
it('should set array of masks and also check *.htm, *.html, *.xhtml', function() {
348+
configuration.load({
349+
extract: ['foo', 'bar']
350+
});
351+
expect(configuration.getExtractFileMasks()).to.deep.equal(['foo', 'bar']);
352+
});
353+
347354
it('should throw an exception when set wrong string value', function() {
348355
expect(function() {
349356
configuration.load({
@@ -354,38 +361,59 @@ describe('config/configuration', function() {
354361
});
355362

356363
describe('shouldExtractFile', function() {
357-
it('should be check *.htm, *.html, *.xhtml by default', function() {
364+
it('should not check anything by default', function() {
358365
configuration.load({});
359-
expect(!!configuration.shouldExtractFile('file.htm')).to.equal(true);
360-
expect(!!configuration.shouldExtractFile('file.html')).to.equal(true);
361-
expect(!!configuration.shouldExtractFile('file.xhtml')).to.equal(true);
362-
expect(!!configuration.shouldExtractFile('foo/file.htm')).to.equal(true);
363-
expect(!!configuration.shouldExtractFile('foo/file.html')).to.equal(true);
364-
expect(!!configuration.shouldExtractFile('foo/file.xhtml')).to.equal(true);
365-
expect(!configuration.shouldExtractFile('file.txt')).to.equal(true);
366-
expect(!configuration.shouldExtractFile('file.ht')).to.equal(true);
367-
expect(!configuration.shouldExtractFile('file.html.tmp')).to.equal(true);
368-
expect(!configuration.shouldExtractFile('smth.html/file.txt')).to.equal(true);
369-
});
370-
371-
it('should set array of masks', function() {
366+
expect(configuration.shouldExtractFile('file.htm')).to.equal(false);
367+
expect(configuration.shouldExtractFile('file.html')).to.equal(false);
368+
expect(configuration.shouldExtractFile('file.xhtml')).to.equal(false);
369+
expect(configuration.shouldExtractFile('foo/file.htm')).to.equal(false);
370+
expect(configuration.shouldExtractFile('foo/file.html')).to.equal(false);
371+
expect(configuration.shouldExtractFile('foo/file.xhtml')).to.equal(false);
372+
373+
expect(configuration.shouldExtractFile('file.txt')).to.equal(false);
374+
expect(configuration.shouldExtractFile('file.ht')).to.equal(false);
375+
expect(configuration.shouldExtractFile('file.html.tmp')).to.equal(false);
376+
expect(configuration.shouldExtractFile('smth.html/file.txt')).to.equal(false);
377+
});
378+
379+
it('should check *.htm, *.html, *.xhtml with value true', function() {
372380
configuration.load({
373-
extract: ['foo', 'bar']
381+
extract: true
374382
});
375-
expect(!!configuration.shouldExtractFile('foo')).to.equal(true);
376-
expect(!!configuration.shouldExtractFile('bar')).to.equal(true);
377-
expect(!configuration.shouldExtractFile('baz/foo')).to.equal(true);
378-
expect(!configuration.shouldExtractFile('foo/bar')).to.equal(true);
383+
expect(configuration.shouldExtractFile('file.htm')).to.equal(true);
384+
expect(configuration.shouldExtractFile('file.html')).to.equal(true);
385+
expect(configuration.shouldExtractFile('file.xhtml')).to.equal(true);
386+
expect(configuration.shouldExtractFile('foo/file.htm')).to.equal(true);
387+
expect(configuration.shouldExtractFile('foo/file.html')).to.equal(true);
388+
expect(configuration.shouldExtractFile('foo/file.xhtml')).to.equal(true);
389+
390+
expect(configuration.shouldExtractFile('file.txt')).to.equal(false);
391+
expect(configuration.shouldExtractFile('file.ht')).to.equal(false);
392+
expect(configuration.shouldExtractFile('file.html.tmp')).to.equal(false);
393+
expect(configuration.shouldExtractFile('smth.html/file.txt')).to.equal(false);
379394
});
380395

381-
it('should set `never`', function() {
396+
it('should set array of masks and also check *.htm, *.html, *.xhtml', function() {
382397
configuration.load({
383-
extract: false
398+
extract: ['foo', 'bar']
384399
});
385-
expect(!configuration.shouldExtractFile('file.html')).to.equal(true);
386-
expect(!configuration.shouldExtractFile('foo/file.html')).to.equal(true);
387-
expect(!configuration.shouldExtractFile('file.html.tmp')).to.equal(true);
388-
expect(!configuration.shouldExtractFile('smth.html/file.txt')).to.equal(true);
400+
expect(configuration.shouldExtractFile('foo')).to.equal(true);
401+
expect(configuration.shouldExtractFile('bar')).to.equal(true);
402+
403+
expect(configuration.shouldExtractFile('baz/foo')).to.equal(false);
404+
expect(configuration.shouldExtractFile('foo/bar')).to.equal(false);
405+
406+
expect(configuration.shouldExtractFile('file.htm')).to.equal(false);
407+
expect(configuration.shouldExtractFile('file.html')).to.equal(false);
408+
expect(configuration.shouldExtractFile('file.xhtml')).to.equal(false);
409+
expect(configuration.shouldExtractFile('foo/file.htm')).to.equal(false);
410+
expect(configuration.shouldExtractFile('foo/file.html')).to.equal(false);
411+
expect(configuration.shouldExtractFile('foo/file.xhtml')).to.equal(false);
412+
413+
expect(configuration.shouldExtractFile('file.txt')).to.equal(false);
414+
expect(configuration.shouldExtractFile('file.ht')).to.equal(false);
415+
expect(configuration.shouldExtractFile('file.html.tmp')).to.equal(false);
416+
expect(configuration.shouldExtractFile('smth.html/file.txt')).to.equal(false);
389417
});
390418
});
391419

test/specs/extract-js.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ describe('extract-js', function() {
3838
describe('whitespaces', function() {
3939
it('should be no errors on disallowTrailingWhitespace', function() {
4040
checker.configure({
41-
disallowTrailingWhitespace: true
41+
disallowTrailingWhitespace: true,
42+
extract: true
4243
});
4344

4445
return checker.extractFile('./test/data/extract/index.html').then(function(errors) {
@@ -48,7 +49,8 @@ describe('extract-js', function() {
4849

4950
it('should be errors on disallowMixedSpacesAndTabs', function() {
5051
checker.configure({
51-
disallowMixedSpacesAndTabs: true
52+
disallowMixedSpacesAndTabs: true,
53+
extract: true
5254
});
5355

5456
return checker.extractFile('./test/data/extract/index.html').then(function(errors) {
@@ -61,7 +63,8 @@ describe('extract-js', function() {
6163

6264
it('should be no errors on validateIndentation', function() {
6365
checker.configure({
64-
validateIndentation: 2
66+
validateIndentation: 2,
67+
extract: true
6568
});
6669

6770
return checker.extractFile('./test/data/extract/always.htm').then(function(errors) {

0 commit comments

Comments
 (0)