Skip to content

Commit

Permalink
Unify lint rules and clean lint (badges#2009)
Browse files Browse the repository at this point in the history
Now that server.js is emptied out, it makes sense to eliminate the differences between the top-level .js files and everything else.
  • Loading branch information
paulmelnikow authored Sep 1, 2018
1 parent 56bcc04 commit 1021411
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .eslintrc-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ parserOptions:
extends:
- "standard-jsx"
- "standard-react"
- "./.eslintrc-preferred.yml"
- "./.eslintrc.yml"

settings:
react:
Expand Down
29 changes: 0 additions & 29 deletions .eslintrc-preferred.yml

This file was deleted.

40 changes: 24 additions & 16 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
parserOptions:
ecmaVersion: 8
extends:
- standard
- prettier

env:
node: true
# We use Promise, Map, and occasional ES6 syntax.
es6: true
mocha: true

parserOptions:
# Override eslint-config-standard, which incorrectly sets this to "module",
# though that setting is only for ES6 modules, not CommonJS modules.
sourceType: "script"

plugins:
- mocha

extends:
# Enable a set of unopinionated, style-agnostic rules which cover many
# likely errors.
- "eslint:recommended"
- "chai-friendly"

rules:
# Disable some rules from eslint:recommended.
Expand All @@ -23,14 +23,22 @@ rules:
# what the functions are doing.
no-unused-vars: ["error", {"args": "none"}]

# We use semicolons.
semi: ["error", "always"]
# These should be disabled by eslint-config-prettier, but are not.
spaced-comment: "off"
standard/object-curly-even-spacing: "off"
one-var: "off"

# We keep whitespace cleaned up.
no-trailing-spaces: "error"
eol-last: "error"
object-curly-spacing: ["error", "always"]
comma-dangle: ["error", "always-multiline"]
# Shields additions.
no-var: "error"
prefer-const: "error"
strict: "error"
arrow-body-style: ["error", "as-needed"]

# Mocha-related.
mocha/no-exclusive-tests: "error"
mocha/no-mocha-arrows: "error"
mocha/prefer-arrow-callback: "error"

# Chai friendly.
no-unused-expressions: "off"
chai-friendly/no-unused-expressions: "error"
20 changes: 11 additions & 9 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

// Have you identified a contributing guideline that should be included here?
// Please open a pull request!
//
Expand Down Expand Up @@ -43,7 +45,7 @@ message([
`@${danger.github.pr.user.login}!`,
].join(''));

if (targetBranch != 'master') {
if (targetBranch !== 'master') {
const message = `This PR targets \`${targetBranch}\``;
const idea = 'It is likely that the target branch should be `master`';
warn(`${message} - <i>${idea}</i>`);
Expand Down Expand Up @@ -99,10 +101,10 @@ if (capitals.created || underscores.created) {
].join(''));
}

const all_files = danger.git.created_files.concat(danger.git.modified_files);
const allFiles = danger.git.created_files.concat(danger.git.modified_files);

all_files.forEach(function(file) {
danger.git.diffForFile(file).then(function(diff) {
allFiles.forEach(file => {
danger.git.diffForFile(file).then(diff => {
if (/\+.*assert[(.]/.test(diff.diff)) {
warn([
`Found 'assert' statement added in \`${file}\`. <br>`,
Expand All @@ -117,23 +119,23 @@ function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}

const affectedServices = all_files
.map(function(file) {
const affectedServices = allFiles
.map(file => {
const match = file.match(/^services\/(.+)\/.+\.service.js$/);
return match ? match[1] : undefined;
})
.filter(Boolean)
.filter(onlyUnique);

const testedServices = all_files
.map(function(file) {
const testedServices = allFiles
.map(file => {
const match = file.match(/^services\/(.+)\/.+\.tester.js$/);
return match ? match[1] : undefined;
})
.filter(Boolean)
.filter(onlyUnique);

affectedServices.forEach(function(service) {
affectedServices.forEach(service => {
if (testedServices.indexOf(service) === -1) {
warn(
[
Expand Down
1 change: 0 additions & 1 deletion lib/.eslintrc.yml

This file was deleted.

2 changes: 2 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const envFlag = require('node-env-flag');
const webpack = require('webpack');
const shouldAnalyze = envFlag(process.env.ANALYZE);
Expand Down
75 changes: 38 additions & 37 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const dom = require('xmldom').DOMParser;
const { DOMParser } = require('xmldom');
const jp = require('jsonpath');
const path = require('path');
const xpath = require('xpath');
Expand Down Expand Up @@ -95,9 +95,9 @@ githubConstellation.initialize(camp);

suggest.setRoutes(config.cors.allowedOrigin, githubApiProvider, camp);

camp.notfound(/\.(svg|png|gif|jpg|json)/, function(query, match, end, request) {
var format = match[1];
var badgeData = getBadgeData("404", query);
camp.notfound(/\.(svg|png|gif|jpg|json)/, (query, match, end, request) => {
const format = match[1];
const badgeData = getBadgeData("404", query);
badgeData.text[1] = 'badge not found';
badgeData.colorscheme = 'red';
// Add format to badge data.
Expand All @@ -106,7 +106,7 @@ camp.notfound(/\.(svg|png|gif|jpg|json)/, function(query, match, end, request) {
makeSend(format, request.res, end)(svg);
});

camp.notfound(/.*/, function(query, match, end, request) {
camp.notfound(/.*/, (query, match, end, request) => {
end(null, { template: '404.html' });
});

Expand All @@ -122,14 +122,14 @@ camp.route(/^\/badge\/dynamic\/(json|xml|yaml)\.(svg|png|gif|jpg|json)$/,
cache({
queryParams: ['uri', 'url', 'query', 'prefix', 'suffix'],
handler: function(query, match, sendBadge, request) {
var type = match[1];
var format = match[2];
var prefix = query.prefix || '';
var suffix = query.suffix || '';
var pathExpression = query.query;
var requestOptions = {};
const type = match[1];
const format = match[2];
const prefix = query.prefix || '';
const suffix = query.suffix || '';
const pathExpression = query.query;
let requestOptions = {};

var badgeData = getBadgeData('custom badge', query);
const badgeData = getBadgeData('custom badge', query);

if (!query.uri && !query.url || !query.query){
setBadgeColor(badgeData, 'red');
Expand All @@ -138,8 +138,9 @@ cache({
return;
}

let url
try {
var url = encodeURI(decodeURIComponent(query.url || query.uri));
url = encodeURI(decodeURIComponent(query.url || query.uri));
} catch(e){
setBadgeColor(badgeData, 'red');
badgeData.text[1] = 'malformed url';
Expand Down Expand Up @@ -183,18 +184,18 @@ cache({
let innerText = [];
switch (type){
case 'json':
data = (typeof data == 'object' ? data : JSON.parse(data));
data = (typeof data === 'object' ? data : JSON.parse(data));
data = jp.query(data, pathExpression);
if (!data.length) {
throw 'no result';
throw Error('no result');
}
innerText = data;
break;
case 'xml':
data = new dom().parseFromString(data);
data = new DOMParser().parseFromString(data);
data = xpath.select(pathExpression, data);
if (!data.length) {
throw 'no result';
throw Error('no result');
}
data.forEach((i,v)=>{
innerText.push(pathExpression.indexOf('@') + 1 ? i.value : i.firstChild.data);
Expand All @@ -204,15 +205,15 @@ cache({
data = yaml.safeLoad(data);
data = jp.query(data, pathExpression);
if (!data.length) {
throw 'no result';
throw Error('no result');
}
innerText = data;
break;
}
badgeData.text[1] = (prefix || '') + innerText.join(', ') + (suffix || '');
} catch (e) {
setBadgeColor(badgeData, 'lightgrey');
badgeData.text[1] = e;
badgeData.text[1] = e.message;
} finally {
sendBadge(format, badgeData);
}
Expand All @@ -222,16 +223,16 @@ cache({

// Any badge.
camp.route(/^\/(:|badge\/)(([^-]|--)*?)-?(([^-]|--)*)-(([^-]|--)+)\.(svg|png|gif|jpg)$/,
function(data, match, end, ask) {
var subject = escapeFormat(match[2]);
var status = escapeFormat(match[4]);
var color = escapeFormat(match[6]);
var format = match[8];
(data, match, end, ask) => {
const subject = escapeFormat(match[2]);
const status = escapeFormat(match[4]);
const color = escapeFormat(match[6]);
const format = match[8];

analytics.noteRequest(data, match);

// Cache management - the badge is constant.
var cacheDuration = (3600*24*1)|0; // 1 day.
const cacheDuration = (3600*24*1)|0; // 1 day.
ask.res.setHeader('Cache-Control', 'max-age=' + cacheDuration);
if (+(new Date(ask.req.headers['if-modified-since'])) >= +serverStartTime) {
ask.res.statusCode = 304;
Expand All @@ -242,7 +243,7 @@ function(data, match, end, ask) {

// Badge creation.
try {
var badgeData = getBadgeData(subject, data);
const badgeData = getBadgeData(subject, data);
badgeData.text[0] = getLabel(subject, data);
badgeData.text[1] = status;
badgeData.colorB = makeColorB(color, data);
Expand All @@ -264,13 +265,13 @@ function(data, match, end, ask) {

// Production cache debugging.
let bitFlip = false;
camp.route(/^\/flip\.svg$/, function(data, match, end, ask) {
var cacheSecs = 60;
camp.route(/^\/flip\.svg$/, (data, match, end, ask) => {
const cacheSecs = 60;
ask.res.setHeader('Cache-Control', 'max-age=' + cacheSecs);
var reqTime = new Date();
var date = (new Date(+reqTime + cacheSecs * 1000)).toGMTString();
const reqTime = new Date();
const date = (new Date(+reqTime + cacheSecs * 1000)).toGMTString();
ask.res.setHeader('Expires', date);
var badgeData = getBadgeData('flip', data);
const badgeData = getBadgeData('flip', data);
bitFlip = !bitFlip;
badgeData.text[1] = bitFlip? 'on': 'off';
badgeData.colorscheme = bitFlip? 'brightgreen': 'red';
Expand All @@ -280,13 +281,13 @@ camp.route(/^\/flip\.svg$/, function(data, match, end, ask) {

// Any badge, old version.
camp.route(/^\/([^/]+)\/(.+).png$/,
function(data, match, end, ask) {
var subject = match[1];
var status = match[2];
var color = data.color;
(data, match, end, ask) => {
const subject = match[1];
const status = match[2];
const color = data.color;

// Cache management - the badge is constant.
var cacheDuration = (3600*24*1)|0; // 1 day.
const cacheDuration = (3600*24*1)|0; // 1 day.
ask.res.setHeader('Cache-Control', 'max-age=' + cacheDuration);
if (+(new Date(ask.req.headers['if-modified-since'])) >= +serverStartTime) {
ask.res.statusCode = 304;
Expand All @@ -297,7 +298,7 @@ function(data, match, end, ask) {

// Badge creation.
try {
var badgeData = { text: [subject, status] };
const badgeData = { text: [subject, status] };
badgeData.colorscheme = color;
const svg = makeBadge(badgeData);
makeSend('png', ask.res, end)(svg);
Expand Down
1 change: 0 additions & 1 deletion services/.eslintrc.yml

This file was deleted.

0 comments on commit 1021411

Please sign in to comment.