.eslintignore generation includes ignored files from projectBuilder
Any file paths registered as ignored with the project builder are now also included/appended to the .eslintignore file. Duplicates are not repeated. Change-Id: I23aa82f5f94f726862ff5235039a90948755b4f2
This commit is contained in:
@@ -29,14 +29,21 @@
|
|||||||
function initializeEslint (generator) {
|
function initializeEslint (generator) {
|
||||||
var fs = generator.fs;
|
var fs = generator.fs;
|
||||||
|
|
||||||
|
// Re-initialize excluded paths.
|
||||||
|
excludedPaths = [];
|
||||||
|
|
||||||
// Read .eslintignore.
|
// Read .eslintignore.
|
||||||
if (fs.exists(ignoreFile)) {
|
if (fs.exists(ignoreFile)) {
|
||||||
excludedPaths = fs.read(ignoreFile)
|
var paths = fs.read(ignoreFile)
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.filter(function (item) {
|
.filter(function (item) {
|
||||||
// Remove empty lines.
|
// Remove empty lines.
|
||||||
return item.length > 0;
|
return item.length > 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
paths.forEach(function (item) {
|
||||||
|
excludedPaths.push(item);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read .eslintrc
|
// Read .eslintrc
|
||||||
@@ -65,11 +72,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the content of our .eslintignore file from the configured list of excluded paths.
|
* Generate the content of our .eslintignore file from the configured list of excluded paths,
|
||||||
|
* as well as any project-level configured ignoreFiles.
|
||||||
*
|
*
|
||||||
* @returns {string} The content of the .eslintignore file.
|
* @returns {string} The content of the .eslintignore file.
|
||||||
*/
|
*/
|
||||||
function buildEslintIgnore () {
|
function buildEslintIgnore () {
|
||||||
|
var ignoredFiles = projectBuilder.getIgnoredFiles();
|
||||||
|
ignoredFiles.forEach(function (item) {
|
||||||
|
if (excludedPaths.indexOf(item) === -1) {
|
||||||
|
excludedPaths.push(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return excludedPaths.sort().join('\n');
|
return excludedPaths.sort().join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -125,6 +125,7 @@
|
|||||||
mockGenerator.fs.write('.eslintignore', mockEslintIgnore.join('\n'));
|
mockGenerator.fs.write('.eslintignore', mockEslintIgnore.join('\n'));
|
||||||
|
|
||||||
eslint.init(mockGenerator);
|
eslint.init(mockGenerator);
|
||||||
|
eslint.prompt(mockGenerator);
|
||||||
eslint.configure(mockGenerator);
|
eslint.configure(mockGenerator);
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
var files = projectBuilder.getIncludedFiles();
|
||||||
@@ -137,11 +138,47 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should include any files flagged as ignored in the project builder.',
|
||||||
|
function () {
|
||||||
|
mockGenerator.fs.write('.eslintignore', '');
|
||||||
|
projectBuilder.ignoreFile('foo/bar.json');
|
||||||
|
|
||||||
|
eslint.init(mockGenerator);
|
||||||
|
eslint.prompt(mockGenerator);
|
||||||
|
eslint.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
var ignoreRef = files[0]; // There should only be one file.
|
||||||
|
var ignoreContent = ignoreRef.content().split('\n');
|
||||||
|
expect(ignoreContent.length).toBe(1);
|
||||||
|
|
||||||
|
expect(ignoreContent[0]).toBe('foo/bar.json');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should de-duplicate file paths from multiple locations.',
|
||||||
|
function () {
|
||||||
|
// include 'node_modules' from both an existing file and from the project builder.
|
||||||
|
mockGenerator.fs.write('.eslintignore', ['node_modules'].join('\n'));
|
||||||
|
projectBuilder.ignoreFile('node_modules');
|
||||||
|
|
||||||
|
eslint.init(mockGenerator);
|
||||||
|
eslint.prompt(mockGenerator);
|
||||||
|
eslint.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
var ignoreRef = files[0]; // There should only be one file.
|
||||||
|
var ignoreContent = ignoreRef.content().split('\n');
|
||||||
|
expect(ignoreContent.length).toBe(1);
|
||||||
|
|
||||||
|
expect(ignoreContent[0]).toBe('node_modules');
|
||||||
|
});
|
||||||
|
|
||||||
it('should sort the ignored files.',
|
it('should sort the ignored files.',
|
||||||
function () {
|
function () {
|
||||||
mockGenerator.fs.write('.eslintignore', mockEslintIgnore.join('\n'));
|
mockGenerator.fs.write('.eslintignore', mockEslintIgnore.join('\n'));
|
||||||
|
|
||||||
eslint.init(mockGenerator);
|
eslint.init(mockGenerator);
|
||||||
|
eslint.prompt(mockGenerator);
|
||||||
eslint.configure(mockGenerator);
|
eslint.configure(mockGenerator);
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
var files = projectBuilder.getIncludedFiles();
|
||||||
@@ -157,6 +194,7 @@
|
|||||||
mockGenerator.fs.write('.eslintignore', ['1_one', '', '2_two', ''].join('\n'));
|
mockGenerator.fs.write('.eslintignore', ['1_one', '', '2_two', ''].join('\n'));
|
||||||
|
|
||||||
eslint.init(mockGenerator);
|
eslint.init(mockGenerator);
|
||||||
|
eslint.prompt(mockGenerator);
|
||||||
eslint.configure(mockGenerator);
|
eslint.configure(mockGenerator);
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
var files = projectBuilder.getIncludedFiles();
|
||||||
@@ -171,6 +209,7 @@
|
|||||||
mockGenerator.fs.write('.eslintignore', '');
|
mockGenerator.fs.write('.eslintignore', '');
|
||||||
|
|
||||||
eslint.init(mockGenerator);
|
eslint.init(mockGenerator);
|
||||||
|
eslint.prompt(mockGenerator);
|
||||||
eslint.configure(mockGenerator);
|
eslint.configure(mockGenerator);
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
|||||||
Reference in New Issue
Block a user