Skip to content

Commit

Permalink
Fixed linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aileen committed May 2, 2018
1 parent df66855 commit 2068489
Show file tree
Hide file tree
Showing 28 changed files with 513 additions and 512 deletions.
12 changes: 6 additions & 6 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var express = require('express'),
app = express(),
scanHbs = hbs.create();


// Configure express
app.set('x-powered-by', false);
app.set('query parser', false);
Expand Down Expand Up @@ -42,15 +41,15 @@ app.get('/example/', function (req, res) {
});
});

app.post('/',
upload.single('theme'),
app.post('/',
upload.single('theme'),
function (req, res, next) {
var zip = {
path: req.file.path,
path: req.file.path,
name: req.file.originalname
};
debug('Uploaded: ' + zip.name + ' to ' + zip.path);

gscan.checkZip(zip).then(function processResult(theme) {
debug('Checked: ' + zip.name);
res.theme = theme;
Expand All @@ -76,9 +75,10 @@ app.use(function (req, res, next) {
next(new errors.NotFoundError({message: 'Page not found'}));
});

// eslint-disable-next-line no-unused-vars
app.use(function (err, req, res, next) {
req.err = err;
res.render('error', {message: err.message, stack: err.stack});
});

server.start(app);
server.start(app);
1 change: 1 addition & 0 deletions app/public/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-env node */
module.exports = {
plugins: ['ghost'],
extends: [
Expand Down
62 changes: 34 additions & 28 deletions app/public/js/gscan.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,52 @@
(function ($) {

function timeSince(date) {

var seconds = Math.floor((new Date() - date) / 1000);
var interval = Math.floor(seconds / 31536000);

if (interval >= 1) {
if(interval===1)
return interval + " year";
else
return interval + " years";
if (interval === 1) {
return interval + ' year';
} else {
return interval + ' years';
}
}
interval = Math.floor(seconds / 2592000);
if (interval >= 1) {
if(interval===1)
return interval + " month";
else
return interval + " months";
if (interval === 1) {
return interval + ' month';
} else {
return interval + ' months';
}
}
interval = Math.floor(seconds / 86400);
if (interval >= 1) {
if(interval===1)
return interval + " day";
else
return interval + " days";
if (interval === 1) {
return interval + ' day';
} else {
return interval + ' days';
}
}
interval = Math.floor(seconds / 3600);
if (interval >= 1) {
if(interval===1)
return interval + " hour";
else
return interval + " hours";
if (interval === 1) {
return interval + ' hour';
} else {
return interval + ' hours';
}
}
interval = Math.floor(seconds / 60);
if (interval >= 1) {
if(interval===1)
return interval + " minute";
else
return interval + " minutes";
if (interval === 1) {
return interval + ' minute';
} else {
return interval + ' minutes';
}
}
if (Math.floor(seconds) === 1) {
return Math.floor(seconds) + ' second';
} else {
return Math.floor(seconds) + ' seconds';
}
if(Math.floor(seconds)===1)
return Math.floor(seconds) + " second";
else
return Math.floor(seconds) + " seconds";
}
$(document).ready(function ($) {
if ($('#theme')[0]) {
Expand All @@ -56,20 +60,22 @@
/** Latest News **/
if ($('.myblogs-latest-news').length && window.ghost) {
$.get(window.ghost.url.api('posts', {limit: 1, include: 'author'}), function (json) {
/* eslint-disable camelcase */
var item = json.posts[0],
parsed_date = new Date(item.published_at),
image_url = item.author.image.substr(0, 2) === '//' ? item.author.image : '//dev.ghost.org/' + item.author.image,
news_html = '<p><a href="https://dev.ghost.org' + item.url + '">' + item.title + '</a></p>' +
'<span class="meta">' +
'<img src="' + image_url + '" />' +
'<time title="' + parsed_date + '">' + timeSince(parsed_date) + ' ago</time> by ' + item.author.name + '</span>';
$(".myblogs-latest-news").html(news_html);
$('.myblogs-latest-news').html(news_html);

/* eslint-disable camelcase */
});
}

/** Toggle Details **/
if ($('.toggle-details').length) {

$('.toggle-details').on('click', function () {
if ($(this).find('~ .details').is(':hidden')) {
$(this).find('~ .details').show();
Expand Down
10 changes: 6 additions & 4 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

var pkgJson = require('../package.json'),
program = require('commander'),
_ = require('lodash'),
chalk = require('chalk'),
gscan = require('../lib'),
_ = require('lodash'),
chalk = require('chalk'),
gscan = require('../lib'),

themePath = '',
levels;
Expand All @@ -27,6 +27,7 @@ levels = {
feature: chalk.green
};

/* eslint-disable no-console */
function outputResult(result) {
console.log('-', levels[result.level](result.level), result.rule);
}
Expand Down Expand Up @@ -70,7 +71,8 @@ if (!program.args.length) {
return err.code === 'ENOTDIR';
}, function (err) {
console.error(err.message);
console.error('Did you mean to add the -z flag to read a zip file?')
console.error('Did you mean to add the -z flag to read a zip file?');
/* eslint-enable no-console */
});
}
}
6 changes: 3 additions & 3 deletions lib/checker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var Promise = require('bluebird'),
_ = require('lodash'),
var Promise = require('bluebird'),
_ = require('lodash'),
requireDir = require('require-dir'),
readTheme = require('./read-theme'),
readTheme = require('./read-theme'),
checker,
checks;

Expand Down
16 changes: 8 additions & 8 deletions lib/checks/001-deprecations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var _ = require('lodash'),
var _ = require('lodash'),
path = require('path'),
fs = require('fs-extra'),
checkDeprecations;
Expand Down Expand Up @@ -121,19 +121,19 @@ checkDeprecations = function checkDeprecations(theme, themePath) {
ruleCode: 'GS001-DEPR-C0H'
},
{
cssRegEx: /\.archive-template[\s\{]/g,
cssRegEx: /\.archive-template[\s{]/g,
className: '.archive-template',
css: true,
ruleCode: 'GS001-DEPR-CSS-AT'
},
{
cssRegEx: /\.page[\s\{]/g,
cssRegEx: /\.page[\s{]/g,
className: '.page',
css: true,
ruleCode: 'GS001-DEPR-CSS-PA'
},
{
cssRegEx: /\.page-template-\w+[\s\{]/g,
cssRegEx: /\.page-template-\w+[\s{]/g,
className: '.page-template-slug',
css: true,
ruleCode: 'GS001-DEPR-CSS-PATS'
Expand All @@ -142,7 +142,7 @@ checkDeprecations = function checkDeprecations(theme, themePath) {

_.each(checks, function (check) {
_.each(theme.files, function (themeFile) {
var template = themeFile.file.match(/^[^\/]+.hbs$/) || themeFile.file.match(/^partials[\/\\]+(.*)\.hbs$/),
var template = themeFile.file.match(/^[^/]+.hbs$/) || themeFile.file.match(/^partials[/\\]+(.*)\.hbs$/),
css = themeFile.file.match(/\.css/),
cssDeprecations;

Expand Down Expand Up @@ -184,9 +184,9 @@ checkDeprecations = function checkDeprecations(theme, themePath) {
}
});

if (theme.results.pass.indexOf(check.ruleCode) === -1 && !theme.results.fail.hasOwnProperty(check.ruleCode)) {
theme.results.pass.push(check.ruleCode);
}
if (theme.results.pass.indexOf(check.ruleCode) === -1 && !theme.results.fail.hasOwnProperty(check.ruleCode)) {
theme.results.pass.push(check.ruleCode);
}
});

return theme;
Expand Down
4 changes: 2 additions & 2 deletions lib/checks/002-comment-id.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var _ = require('lodash'),
checkCommentID;

checkCommentID = function checkCommentID(theme, themePath) {
checkCommentID = function checkCommentID(theme) {
var checks = [
// Check 1:
// Look for instances of: this.page.identifier = 'ghost-{{id}}';
Expand All @@ -20,7 +20,7 @@ checkCommentID = function checkCommentID(theme, themePath) {

_.each(checks, function (check) {
_.each(theme.files, function (themeFile) {
var template = themeFile.file.match(/^[^\/]+.hbs$/) || themeFile.file.match(/^partials[\/\\]+(.*)\.hbs$/);
var template = themeFile.file.match(/^[^/]+.hbs$/) || themeFile.file.match(/^partials[/\\]+(.*)\.hbs$/);

if (template) {
if (themeFile.content.match(check.regex)) {
Expand Down
14 changes: 8 additions & 6 deletions lib/checks/005-template-compile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var _ = require('lodash'),
hbs = require('express-hbs'),
spec = require('../spec.js'),
var _ = require('lodash'),
hbs = require('express-hbs'),
spec = require('../spec.js'),
checkTemplatesCompile,
fakeData = require('../faker');

Expand Down Expand Up @@ -30,7 +30,7 @@ checkTemplatesCompile = function checkTemplatesCompile(theme) {
});

_.each(theme.files, function (themeFile) {
var templateTest = themeFile.file.match(/^[^\/]+.hbs$/),
var templateTest = themeFile.file.match(/^[^/]+.hbs$/),
compiled;

// If this is a main template, test compiling it properly
Expand All @@ -39,7 +39,9 @@ checkTemplatesCompile = function checkTemplatesCompile(theme) {
// When we read the theme, we precompile, here we compile with registered partials and helpers
// Which will let us detect any missing partials, helpers or parse errors
compiled = localHbs.handlebars.compile(themeFile.content, {
knownHelpers: _.zipObject(spec.knownHelpers, _.map(spec.knownHelpers, function() { return true; })),
knownHelpers: _.zipObject(spec.knownHelpers, _.map(spec.knownHelpers, function () {
return true;
})),
knownHelpersOnly: true
});

Expand All @@ -50,7 +52,7 @@ checkTemplatesCompile = function checkTemplatesCompile(theme) {
if (error.message.match(/you specified knownhelpersOnly/gi)) {
try {
missingHelper = error.message.match(/but\sused\sthe\sunknown\shelper\s(.*)\s-/)[1];
} catch(err) {
} catch (err) {
missingHelper = 'unknown helper name';
}

Expand Down
4 changes: 2 additions & 2 deletions lib/checks/010-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ _private.validatePackageJSONFields = function validatePackageJSONFields(packageJ
failed.push(packageJSONValidationRules.nameIsLowerCase);
}

if (packageJSON.name && !packageJSON.name.match(/^[a-z0-9]+(\-?[a-z0-9]+)*$/gi)) {
if (packageJSON.name && !packageJSON.name.match(/^[a-z0-9]+(-?[a-z0-9]+)*$/gi)) {
failed.push(packageJSONValidationRules.nameIsHyphenated);
}

Expand Down Expand Up @@ -85,7 +85,7 @@ _private.getFailedRules = function getFailedRules(keys) {
}));
};

module.exports = function checkPackageJSON(theme, themePath) {
module.exports = function checkPackageJSON(theme) {
var packageJSONPath = path.join(theme.path, packageJSONFile);

// CASE: package.json must be present (if not, all validation rules fail)
Expand Down
28 changes: 14 additions & 14 deletions lib/checks/020-theme-structure.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var _ = require('lodash'),
var _ = require('lodash'),
checkThemeStructure;

// TODO: template inspection
Expand All @@ -18,19 +18,19 @@ var _ = require('lodash'),

checkThemeStructure = function checkThemeStructure(theme) {
var checks = [
{
path: 'index.hbs',
ruleCode: 'GS020-INDEX-REQ'
},
{
path: 'post.hbs',
ruleCode: 'GS020-POST-REQ'
},
{
path: 'default.hbs',
ruleCode: 'GS020-DEF-REC'
}
];
{
path: 'index.hbs',
ruleCode: 'GS020-INDEX-REQ'
},
{
path: 'post.hbs',
ruleCode: 'GS020-POST-REQ'
},
{
path: 'default.hbs',
ruleCode: 'GS020-DEF-REC'
}
];

_.each(checks, function (check) {
if (!_.some(theme.files, {file: check.path})) {
Expand Down
5 changes: 2 additions & 3 deletions lib/checks/030-assets.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var _ = require('lodash'),
var _ = require('lodash'),
path = require('path'),
fs = require('fs'),
checkAssets;
Expand Down Expand Up @@ -33,10 +33,9 @@ checkAssets = function checkAssets(theme, themePath) {
if (stats.isSymbolicLink()) {
failures.push({ref: theme.file});
}
} catch(err) {
} catch (err) {
// ignore
}

});

if (failures.length > 0) {
Expand Down
Loading

0 comments on commit 2068489

Please sign in to comment.