Skip to content

Commit

Permalink
feat(dependencies): update eslint to the latest and fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Juned Kazi committed Feb 17, 2020
1 parent 395f007 commit 5a2fd85
Show file tree
Hide file tree
Showing 33 changed files with 109 additions and 142 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ insert_final_newline = true
trim_trailing_whitespace = false
[*.json]
indent_size = 2
[.eslintrc]
indent_size = 2
13 changes: 8 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"parserOptions": {
"ecmaVersion": 8
},
"ecmaFeatures": {
"modules": true
"ecmaVersion": 8,
"sourceType": "module",
"ecmaFeatures": {
"impliedStrict": true
}
},
"env": {
"es6": true,
Expand All @@ -20,6 +21,8 @@
"dot-notation": 0,
"no-debugger": 2,
"no-undef": 2,
"no-unused-vars": 2
"no-unused-vars": 2,
"semi": 2,
"arrow-parens": [2, "as-needed"]
}
}
2 changes: 1 addition & 1 deletion bin/stencil-bundle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe('Stencil Bundle', () => {
expect(err.message).to.contain('no such file or directory');
done();
});
})
});

function getThemeConfigStub() {
const rawConfig = {
Expand Down
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = {extends: ['@commitlint/config-conventional']}
module.exports = {extends: ['@commitlint/config-conventional']};
2 changes: 1 addition & 1 deletion constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ const path = require('path');
const packagePath = path.join(process.cwd(), 'package.json');
const packageInfo = require(packagePath);

module.exports = { packageInfo }
module.exports = { packageInfo };
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function logError(err) {
gulp.task('install-private-dependencies', installPrivateDependencies);
gulp.task('bump', bumpTask);
gulp.task('deploy-webpack', deployWebpack);
gulp.task('changelog', (done) => changelog.changelogTask({}, done));
gulp.task('changelog', done => changelog.changelogTask({}, done));
gulp.task('uninstall-private-dependencies', uninstallPrivateDependencies);
gulp.task('push', pushTask);
gulp.task('release', gulp.series('install-private-dependencies', 'bump', 'deploy-webpack', 'changelog', 'uninstall-private-dependencies', 'push'));
46 changes: 5 additions & 41 deletions lib/bundle-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var OBJECTS_TO_VALIDATE = [

var _ = require('lodash');
var Async = require('async');
var Eslint = require('eslint').CLIEngine;
var Fs = require('fs');
var sizeOf = require('image-size');
var Path = require('path');
Expand All @@ -41,10 +40,6 @@ function BundleValidator(themePath, themeConfig, isPrivate) {
if (!this.isPrivate) {
this.validationTasks.push(validateMetaImages.bind(this));
}

if (existsSync(Path.join(this.themePath, '.eslintrc'))) {

This comment has been minimized.

Copy link
@Ash-Matter

Ash-Matter May 25, 2020

@junedkazi Why is the use of .eslintrc removed from the build?

this.validationTasks.push(runLintTask);
}
}

/**
Expand All @@ -54,7 +49,7 @@ function BundleValidator(themePath, themeConfig, isPrivate) {
BundleValidator.prototype.validateTheme = function (callback) {
Async.series(this.validationTasks, function (error, result) {
return callback(error, result);
})
});
};

/**
Expand All @@ -79,7 +74,7 @@ function validateThemeConfiguration(callback) {

if (!this.themeConfig.configExists()) {
return callback(
new Error('You must have a '.red + 'config.json'.cyan + ' file in your top level theme directory.')
new Error('You must have a '.red + 'config.json'.cyan + ' file in your top level theme directory.'),
);
}

Expand All @@ -89,7 +84,7 @@ function validateThemeConfiguration(callback) {

// Validate against the theme registry config schema
if (this.isPrivate) {
validationSchema = './privateThemeConfig.schema.json'
validationSchema = './privateThemeConfig.schema.json';
}

validation = v.validate(this.themeConfig.getRawConfig(), require(validationSchema));
Expand Down Expand Up @@ -144,7 +139,7 @@ function validateMetaImages(callback) {
+ '\r\nValid types ('.red + VALID_IMAGE_TYPES.join(', ').red + ')'.red));
} else if (!Fs.existsSync(imagePath)) {
return callback(
new Error('The path you specified for your "meta.composed_image" does not exist.'.red)
new Error('The path you specified for your "meta.composed_image" does not exist.'.red),
);
} else {
(function (path) {
Expand Down Expand Up @@ -248,37 +243,6 @@ function isValidImageType(imagePath) {
return _.includes(VALID_IMAGE_TYPES, ext);
}

function runLintTask(callback) {
console.log('Running ESLint...');
var options = {
ignorePattern: [
'assets/js/**/*.spec.js',
'assets/js/dependency-bundle.js',
],
};

var cli = new Eslint(options);
var report = cli.executeOnFiles([Path.join(process.cwd(), 'assets', 'js')]);
var formatter = cli.getFormatter();

console.log(formatter(report.results));

if (report.errorCount !== 0) {
callback(new Error('Please fix the above Javascript errors.'));
}

callback(null, true);
}

function existsSync(file) {
try {
Fs.accessSync(file);
return true;
} catch (e) {
return false;
}
}

function validateImage(path, width, height, cb) {
var MAX_SIZE_COMPOSED = 1048576 * 2; //2MB
var MAX_SIZE_MOBILE = 1048576; //1MB
Expand Down Expand Up @@ -312,7 +276,7 @@ function validateImage(path, width, height, cb) {
+ 'is greater than allowed size ' + MAX_SIZE_MOBILE + '\n';
}

if (imageWidth !== width || imageHeight != height) {
if (imageWidth !== width || imageHeight !== height) {
failureMessage += 'Image at (' + path + ') has incorrect dimensions ('
+ imageWidth + 'x' + imageHeight + ') should be' + '(' + width + 'x' + height + ')';
return cb(new Error(failureMessage));
Expand Down
6 changes: 3 additions & 3 deletions lib/bundle-validator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('BundleValidator', function () {

sizeOfSpy.restore();
done();
})
});
});


Expand All @@ -46,7 +46,7 @@ describe('BundleValidator', function () {

sizeOfSpy.restore();
done();
})
});
});

it ('should validate returned objects exist in templates', function (done) {
Expand Down Expand Up @@ -99,5 +99,5 @@ describe('BundleValidator', function () {
expect(err.message).to.equal('Missing required objects/properties: footer.scripts');
done();
});
})
});
});
2 changes: 1 addition & 1 deletion lib/json-lint.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ describe('json-lint', function () {

expect(throws).throw(Error, !file);
done();
})
});
});
2 changes: 1 addition & 1 deletion lib/release/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const dateFormatOptions = {
function askQuestions(themeConfig, githubToken, remotes, callback) {
const remoteChoices = remotes.map(remote => {
return { value: remote, name: `${remote.name}: ${remote.url}` };
})
});

const currentVersion = themeConfig.getVersion();

Expand Down
2 changes: 1 addition & 1 deletion lib/release/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = () => {

saveGithubToken(answers.githubToken);

doRelease(answers, (err) => {
doRelease(answers, err => {
if (err) {
return printError(err.message);
}
Expand Down
18 changes: 9 additions & 9 deletions lib/stencil-bundle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const MEGABYTE = 1048576
const MAX_SIZE_BUNDLE = MEGABYTE * 50;
const MEGABYTE = 1048576;
const MAX_SIZE_BUNDLE = MEGABYTE * 50;
const PATHS_TO_ZIP = [
'assets/**/*',
'!assets/cdn/**',
Expand Down Expand Up @@ -69,7 +69,7 @@ function Bundle(themePath, themeConfig, rawConfig, options) {
console.log('ok'.green + ' -- Theme task Finished');
callback();
});
}
};
}

this.tasks = tasks;
Expand Down Expand Up @@ -110,7 +110,7 @@ Bundle.prototype.getCssAssembleTask = function (compiler) {

console.log('%s Parsing Started...', compiler.toUpperCase());
Fs.readdir(basePath, (err, files) => {
const filterFiles = files.filter((file) => {
const filterFiles = files.filter(file => {
return file.substr(-(compiler.length + 1)) === '.' + compiler;
});
Async.map(filterFiles, (file, mapCallback) => {
Expand Down Expand Up @@ -140,7 +140,7 @@ Bundle.prototype.assembleTemplatesTask = function (callback) {
return callback(err);
}

const partials = files.map((file) => {
const partials = files.map(file => {
return Upath.toUnix(file.replace(this.templatesPath + Path.sep, '').replace(/\.html$/, ''));
});

Expand Down Expand Up @@ -222,7 +222,7 @@ Bundle.prototype.getJspmBundleTask = function (jspmConfig) {
}).catch(err => {
callback(err);
});
}
};
};

Bundle.prototype.generateManifest = function (taskResults, callback) {
Expand Down Expand Up @@ -263,7 +263,7 @@ function detectCycles(results, callback) {
new Cycles(results).detect();
callback();
} catch (err) {
callback(err)
callback(err);
}
}

Expand Down Expand Up @@ -343,7 +343,7 @@ function bundleThemeFiles(archive, themePath, configuration) {
if (configuration.jspm) {
archive.append(
Fs.createReadStream(configuration.jspm.tmpBundleFile),
{ name: configuration.jspm.bundle_location }
{ name: configuration.jspm.bundle_location },
);
}

Expand All @@ -363,7 +363,7 @@ function bundleThemeFiles(archive, themePath, configuration) {
function bundleParsedFiles(archive, taskResults) {
const archiveJsonFile = (data, name) => {
archive.append(JSON.stringify(data, null, 2), { name });
}
};
const failedTemplates = [];
for (let task in taskResults) {
let data = taskResults[task];
Expand Down
2 changes: 1 addition & 1 deletion lib/stencil-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internals.parseAnswers = function(JspmAssembler, ThemeConfig, dotStencilFile, do
'jspm.jspm_packages_path'.cyan +
' setting in your theme\'s '.red +
'config.json'.cyan +
' file to make sure it\'s correct.'.red
' file to make sure it\'s correct.'.red,
);
}

Expand Down
12 changes: 6 additions & 6 deletions lib/stencil-pull.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ utils.downloadThemeConfig = (options, callback) => {
request(options.downloadUrl)
.pipe(fs.createWriteStream(tempThemePath))
.on('finish', () => resolve(tempThemePath))
.on('error', reject)
.on('error', reject),
)
)
.then(tempThemePath =>
Expand Down Expand Up @@ -81,8 +81,8 @@ utils.downloadThemeConfig = (options, callback) => {
});
});
});
})
)
}),
),
)
.then(
liveStencilConfig =>
Expand All @@ -94,13 +94,13 @@ utils.downloadThemeConfig = (options, callback) => {
}

resolve();
})
)
}),
),
)
.then(() => {
cleanupCallback();
callback(null, options);
})
.catch(callback);
})
});
};
2 changes: 1 addition & 1 deletion lib/stencil-push.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const mockDb = {
set data(data) {
this._data = data;
},
}
};

describe('stencil push', () => {
let sandbox;
Expand Down
12 changes: 6 additions & 6 deletions lib/stencil-push.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ utils.promptUserToDeleteThemesIfNecessary = (options, callback) => {
const oldestTheme = options.themes
.filter(theme => theme.is_private && !theme.is_active)
.map(theme => ({ uuid: theme.uuid, updated_at: new Date(theme.updated_at).valueOf() }))
.reduce((prev, current) => prev.updated_at < current.updated_at ? prev : current)
.reduce((prev, current) => prev.updated_at < current.updated_at ? prev : current);
return callback(null, Object.assign({}, options, { themeIdsToDelete: [oldestTheme.uuid] }));
}

Expand All @@ -171,7 +171,7 @@ utils.promptUserToDeleteThemesIfNecessary = (options, callback) => {
message: 'Which theme(s) would you like to delete?',
name: 'themeIdsToDelete',
type: 'checkbox',
validate: (val) => {
validate: val => {
if (val.length > 0) {
return true;
} else {
Expand All @@ -180,7 +180,7 @@ utils.promptUserToDeleteThemesIfNecessary = (options, callback) => {
},
}];

Inquirer.prompt(questions, (answers) => {
Inquirer.prompt(questions, answers => {
callback(null, Object.assign({}, options, answers));
});
};
Expand All @@ -201,15 +201,15 @@ utils.deleteThemesIfNecessary = (options, callback) => {
storeHash: options.storeHash,
themeId,
}, options), cb);
}
};
}), err => {
if (err) {
err.name = 'ThemeDeletionError';
return callback(err);
}

callback(null, options);
})
});
};

utils.uploadBundleAgainIfNecessary = (options, callback) => {
Expand Down Expand Up @@ -319,7 +319,7 @@ utils.getVariations = (options, callback) => {

utils.promptUserForVariation = (options, callback) => {
if (!options.applyTheme) {
return async.nextTick(callback.bind(null, null, options))
return async.nextTick(callback.bind(null, null, options));
}

if (options.variationId) {
Expand Down
Loading

0 comments on commit 5a2fd85

Please sign in to comment.