Features/eslint (#2037)

Fixes #1913

* Drops node 4

* update node engine to >=6 (#2035)

* syncs changes to spacing across different editorconfigs

* adds eslint with minimally invasive configuration- basically moving from 4 to 2 spaces.
This commit is contained in:
Rob Larsen
2018-04-06 17:31:27 -04:00
committed by GitHub
parent 2c8c4ea3c2
commit f121b53023
12 changed files with 7367 additions and 299 deletions

View File

@@ -12,36 +12,36 @@ const dirs = pkg['h5bp-configs'].directories;
function checkString(file, string, done) {
let character = '';
let matchFound = false;
let matchedPositions = 0;
const readStream = fs.createReadStream(file, { 'encoding': 'utf8' });
let character = '';
let matchFound = false;
let matchedPositions = 0;
const readStream = fs.createReadStream(file, {'encoding': 'utf8'});
readStream.on('close', done);
readStream.on('error', done);
readStream.on('readable', function () {
readStream.on('close', done);
readStream.on('error', done);
readStream.on('readable', function () {
// Read file until the string is found
// or the whole file has been read
while (matchFound !== true &&
// Read file until the string is found
// or the whole file has been read
while (matchFound !== true &&
(character = readStream.read(1)) !== null) {
if (character === string.charAt(matchedPositions)) {
matchedPositions += 1;
} else {
matchedPositions = 0;
}
if (character === string.charAt(matchedPositions)) {
matchedPositions += 1;
} else {
matchedPositions = 0;
}
if (matchedPositions === string.length) {
matchFound = true;
}
if (matchedPositions === string.length) {
matchFound = true;
}
}
}
assert.equal(true, matchFound);
this.close();
assert.equal(true, matchFound);
this.close();
});
});
}
@@ -49,37 +49,37 @@ function checkString(file, string, done) {
function runTests() {
const dir = dirs.dist;
const dir = dirs.dist;
describe(`Test if the files from the "${dir}" directory have the expected content`, () => {
it('".htaccess" should have the "ErrorDocument..." line uncommented', (done) => {
const string = '\n\nErrorDocument 404 /404.html\n\n';
checkString(path.resolve(dir, '.htaccess'), string, done);
});
it('"index.html" should contain the correct jQuery version in the CDN URL', (done) => {
const string = `code.jquery.com/jquery-${pkg.devDependencies.jquery}.min.js`;
checkString(path.resolve(dir, 'index.html'), string, done);
});
it('"index.html" should contain the correct jQuery version in the local URL', (done) => {
const string = `js/vendor/jquery-${pkg.devDependencies.jquery}.min.js`;
checkString(path.resolve(dir, 'index.html'), string, done);
});
it('"index.html" should contain the correct Modernizr version in the local URL', (done) => {
const string = `js/vendor/modernizr-${pkg.devDependencies.modernizr}.min.js`;
checkString(path.resolve(dir, 'index.html'), string, done);
});
it('"main.css" should contain a custom banner', function (done) {
const string = `/*! HTML5 Boilerplate v${pkg.version} | ${pkg.license} License | ${pkg.homepage} */\n\n/*\n`;
checkString(path.resolve(dir, 'css/main.css'), string, done);
});
describe(`Test if the files from the "${dir}" directory have the expected content`, () => {
it('".htaccess" should have the "ErrorDocument..." line uncommented', (done) => {
const string = '\n\nErrorDocument 404 /404.html\n\n';
checkString(path.resolve(dir, '.htaccess'), string, done);
});
it('"index.html" should contain the correct jQuery version in the CDN URL', (done) => {
const string = `code.jquery.com/jquery-${pkg.devDependencies.jquery}.min.js`;
checkString(path.resolve(dir, 'index.html'), string, done);
});
it('"index.html" should contain the correct jQuery version in the local URL', (done) => {
const string = `js/vendor/jquery-${pkg.devDependencies.jquery}.min.js`;
checkString(path.resolve(dir, 'index.html'), string, done);
});
it('"index.html" should contain the correct Modernizr version in the local URL', (done) => {
const string = `js/vendor/modernizr-${pkg.devDependencies.modernizr}.min.js`;
checkString(path.resolve(dir, 'index.html'), string, done);
});
it('"main.css" should contain a custom banner', function (done) {
const string = `/*! HTML5 Boilerplate v${pkg.version} | ${pkg.license} License | ${pkg.homepage} */\n\n/*\n`;
checkString(path.resolve(dir, 'css/main.css'), string, done);
});
});
}
runTests();

View File

@@ -10,55 +10,55 @@ import pkg from './../package.json';
const dirs = pkg['h5bp-configs'].directories;
const expectedFilesInArchiveDir = [
`${pkg.name}_v${pkg.version}.zip`
`${pkg.name}_v${pkg.version}.zip`
];
const expectedFilesInDistDir = [
'.editorconfig',
'.gitattributes',
'.gitignore',
'.htaccess',
'404.html',
'browserconfig.xml',
'.editorconfig',
'.gitattributes',
'.gitignore',
'.htaccess',
'404.html',
'browserconfig.xml',
'css/', // for directories, a `/` character
// should be included at the end
'css/main.css',
'css/normalize.css',
'css/', // for directories, a `/` character
// should be included at the end
'css/main.css',
'css/normalize.css',
'doc/',
'doc/TOC.md',
'doc/css.md',
'doc/extend.md',
'doc/faq.md',
'doc/html.md',
'doc/js.md',
'doc/misc.md',
'doc/usage.md',
'doc/',
'doc/TOC.md',
'doc/css.md',
'doc/extend.md',
'doc/faq.md',
'doc/html.md',
'doc/js.md',
'doc/misc.md',
'doc/usage.md',
'favicon.ico',
'humans.txt',
'favicon.ico',
'humans.txt',
'icon.png',
'icon.png',
'img/',
'img/.gitignore',
'img/',
'img/.gitignore',
'index.html',
'index.html',
'js/',
'js/main.js',
'js/plugins.js',
'js/vendor/',
`js/vendor/jquery-${pkg.devDependencies.jquery}.min.js`,
`js/vendor/modernizr-${pkg.devDependencies.modernizr}.min.js`,
'js/',
'js/main.js',
'js/plugins.js',
'js/vendor/',
`js/vendor/jquery-${pkg.devDependencies.jquery}.min.js`,
`js/vendor/modernizr-${pkg.devDependencies.modernizr}.min.js`,
'LICENSE.txt',
'robots.txt',
'site.webmanifest',
'tile-wide.png',
'tile.png'
'LICENSE.txt',
'robots.txt',
'site.webmanifest',
'tile-wide.png',
'tile.png'
];
@@ -66,51 +66,51 @@ const expectedFilesInDistDir = [
function checkFiles(directory, expectedFiles) {
// Get the list of files from the specified directory
const files = glob.sync('**/*', {
'cwd': directory,
'dot': true, // include hidden files
'mark': true // add a `/` character to directory matches
});
// Get the list of files from the specified directory
const files = glob.sync('**/*', {
'cwd': directory,
'dot': true, // include hidden files
'mark': true // add a `/` character to directory matches
});
// Check if all expected files are present in the
// specified directory, and are of the expected type
expectedFiles.forEach( (file) => {
expectedFiles.forEach((file) => {
let ok = false;
const expectedFileType = (file.slice(-1) !== '/' ? 'regular file' : 'directory');
let ok = false;
const expectedFileType = (file.slice(-1) !== '/' ? 'regular file' : 'directory');
// If file exists
if (files.indexOf(file) !== -1) {
// If file exists
if (files.indexOf(file) !== -1) {
// Check if the file is of the correct type
if (file.slice(-1) !== '/') {
// Check if the file is really a regular file
ok = fs.statSync(path.resolve(directory, file)).isFile();
} else {
// Check if the file is a directory
// (Since glob adds the `/` character to directory matches,
// we can simply check if the `/` character is present)
ok = (files[files.indexOf(file)].slice(-1) === '/');
}
// Check if the file is of the correct type
if (file.slice(-1) !== '/') {
// Check if the file is really a regular file
ok = fs.statSync(path.resolve(directory, file)).isFile();
} else {
// Check if the file is a directory
// (Since glob adds the `/` character to directory matches,
// we can simply check if the `/` character is present)
ok = (files[files.indexOf(file)].slice(-1) === '/');
}
}
it(`"${file}" should be present and it should be a ${expectedFileType}`, () =>{
assert.equal(true, ok);
});
}
it(`"${file}" should be present and it should be a ${expectedFileType}`, () =>{
assert.equal(true, ok);
});
// List all files that should be NOT
// be present in the specified directory
(files.filter( (file) => {
return expectedFiles.indexOf(file) === -1;
})).forEach( (file) => {
it(`"${file}" should NOT be present`, () => {
assert(false);
});
});
// List all files that should be NOT
// be present in the specified directory
(files.filter((file) => {
return expectedFiles.indexOf(file) === -1;
})).forEach((file) => {
it(`"${file}" should NOT be present`, () => {
assert(false);
});
});
}
@@ -118,18 +118,18 @@ function checkFiles(directory, expectedFiles) {
function runTests() {
describe('Test if all the expected files, and only them, are present in the build directories', () => {
describe(dirs.archive, () => {
checkFiles(dirs.archive, expectedFilesInArchiveDir);
});
describe(dirs.dist, () => {
checkFiles(dirs.dist, expectedFilesInDistDir);
});
describe('Test if all the expected files, and only them, are present in the build directories', () => {
describe(dirs.archive, () => {
checkFiles(dirs.archive, expectedFilesInArchiveDir);
});
describe(dirs.dist, () => {
checkFiles(dirs.dist, expectedFilesInDistDir);
});
});
}
runTests();