Skip to content

Commit

Permalink
Force eslint (#1777)
Browse files Browse the repository at this point in the history
* git should process linebreak

* npx eslint src/**/*.js --fix

* use let/const in examples.js

* remaining manual fixes

* force eslint

* npm run lint
  • Loading branch information
saschanaz committed Jul 28, 2018
1 parent 4baeae1 commit 273e51e
Show file tree
Hide file tree
Showing 29 changed files with 640 additions and 307 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.json
Expand Up @@ -15,10 +15,10 @@
},
"rules": {
"indent": 0,
"linebreak-style": ["error", "unix"],
"quotes": 0,
"semi": ["error", "always"],
"no-console": 0
"no-console": 0,
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
},
"globals": {
"flushIframes": true,
Expand Down
5 changes: 4 additions & 1 deletion .travis.yml
Expand Up @@ -17,10 +17,13 @@ addons:

cache:
directories:
- node_modules # NPM packages
- node_modules # NPM packages

jobs:
include:
- stage: Run eslint
script:
- npm run lint
- stage: Run headless
script:
- npm run test:headless
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -69,6 +69,7 @@
"copydeps": "node ./tools/copydeps.js",
"handlebars": "handlebars",
"karma": "karma start --single-run",
"lint": "npx eslint src/**/*.js",
"release": "node ./tools/release.js",
"server": "npm start",
"snyk": "snyk",
Expand Down
14 changes: 11 additions & 3 deletions src/core/best-practices.js
Expand Up @@ -15,13 +15,21 @@ export function run() {
for (const bp of bps) {
num++;
const id = window.$.fn.makeID.call([bp], "bp");
const li = hyperHTML`<li><a href="${`#${id}`}">Best Practice ${num}</a>: ${bp.textContent}</li>`;
const li = hyperHTML`<li><a href="${`#${id}`}">Best Practice ${num}</a>: ${
bp.textContent
}</li>`;
ul.appendChild(li);
bp.insertBefore(document.createTextNode(`Best Practice ${num}: `), bp.firstChild);
bp.insertBefore(
document.createTextNode(`Best Practice ${num}: `),
bp.firstChild
);
}
const bpSummary = document.getElementById("bp-summary");
if (bps.length) {
document.head.insertBefore(hyperHTML`<style>${[css]}</style>`, document.head.querySelector("link"));
document.head.insertBefore(
hyperHTML`<style>${[css]}</style>`,
document.head.querySelector("link")
);
if (bpSummary) {
bpSummary.appendChild(hyperHTML`<h2>Best Practices Summary</h2>`);
bpSummary.appendChild(ul);
Expand Down
2 changes: 1 addition & 1 deletion src/core/caniuse.js
Expand Up @@ -195,7 +195,7 @@ function createTableHTML(conf, stats) {
.slice(-numVersions)
.reverse();
const { support, title } = getSupport(latestVersion);
const cssClass= `caniuse-cell ${support}`;
const cssClass = `caniuse-cell ${support}`;
return hyperHTML`
<div class="caniuse-browser">
<button class="${cssClass}" title="${title}">
Expand Down
4 changes: 3 additions & 1 deletion src/core/data-include.js
Expand Up @@ -75,7 +75,9 @@ export function run(conf, doc, cb) {
const text = await response.text();
processResponse(text, id, url);
} catch (err) {
const msg = `\`data-include\` failed: \`${url}\` (${err.message}). See console for details.`;
const msg = `\`data-include\` failed: \`${url}\` (${
err.message
}). See console for details.`;
console.error("data-include failed for element: ", el, err);
pub("error", msg);
}
Expand Down
37 changes: 20 additions & 17 deletions src/core/examples.js
Expand Up @@ -10,9 +10,9 @@ import css from "deps/text!core/css/examples.css";

export const name = "core/examples";

var makeTitle = function(conf, $el, num, report) {
var txt = num > 0 ? " " + num : "";
var $tit = $(
function makeTitle(conf, $el, num, report) {
const txt = num > 0 ? " " + num : "";
const $tit = $(
`<div class='example-title'><span>${conf.l10n.example}${txt}</span></div>`
);
report.title = $el.attr("title");
Expand All @@ -24,42 +24,45 @@ var makeTitle = function(conf, $el, num, report) {
}
$tit.addClass("marker");
return $tit;
};
}

export function run(conf, doc, cb) {
var $exes = $("pre.example, pre.illegal-example, aside.example"),
num = 0;
const $exes = $("pre.example, pre.illegal-example, aside.example");
let num = 0;
if ($exes.length) {
$(doc).find("head link").first().before($("<style/>").text(css));
$exes.each(function(i, ex) {
var $ex = $(ex),
$(doc)
.find("head link")
.first()
.before($("<style/>").text(css));
$exes.each((i, ex) => {
const $ex = $(ex),
report = { number: num, illegal: $ex.hasClass("illegal-example") };
if ($ex.is("aside")) {
num++;
var $tit = makeTitle(conf, $ex, num, report);
const $tit = makeTitle(conf, $ex, num, report);
$ex.prepend($tit);
pub("example", report);
} else {
var inAside = !!$ex.parents("aside").length;
let inAside = !!$ex.parents("aside").length;
if (!inAside) num++;
// reindent
var lines = $ex.html().split("\n");
let lines = $ex.html().split("\n");
while (lines.length && /^\s*$/.test(lines[0])) lines.shift();
while (lines.length && /^\s*$/.test(lines[lines.length - 1]))
lines.pop();
var matches = /^(\s+)/.exec(lines[0]);
const matches = /^(\s+)/.exec(lines[0]);
if (matches) {
var rep = new RegExp("^" + matches[1]);
for (var j = 0; j < lines.length; j++) {
const rep = new RegExp("^" + matches[1]);
for (let j = 0; j < lines.length; j++) {
lines[j] = lines[j].replace(rep, "");
}
}
report.content = lines.join("\n");
$ex.html(lines.join("\n"));
$ex.removeClass("example illegal-example");
// wrap
var $div = $("<div class='example'></div>"),
$tit = makeTitle(conf, $ex, inAside ? 0 : num, report);
const $div = $("<div class='example'></div>");
const $tit = makeTitle(conf, $ex, inAside ? 0 : num, report);
$div.append($tit);
$div.append($ex.clone());
$ex.replaceWith($div);
Expand Down
4 changes: 2 additions & 2 deletions src/core/github.js
Expand Up @@ -4,7 +4,6 @@
* @see https://github.com/w3c/respec/wiki/github
*/

import l10n from "core/l10n";
import { pub } from "core/pubsubhub";

export const name = "core/github";
Expand Down Expand Up @@ -74,7 +73,8 @@ export async function run(conf) {
}
const [org, repo] = ghURL.pathname.split("/").filter(item => item);
if (!org || !repo) {
const msg = "`respecConf.github` URL needs a path with, for example, w3c/my-spec";
const msg =
"`respecConf.github` URL needs a path with, for example, w3c/my-spec";
pub("error", msg);
return;
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/highlight.js
Expand Up @@ -52,7 +52,9 @@ export async function run(conf) {
languages: getLanguageHint(element.classList),
};
worker.addEventListener("message", function listener(ev) {
const { data: { id, code, language, value } } = ev;
const {
data: { id, language, value },
} = ev;
if (id !== msg.id) {
return; // not for us!
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/issues-notes.js
Expand Up @@ -112,9 +112,9 @@ function handleIssues(ins, ghIssues, conf) {
// Add entry to #issue-summary.
var $li = $("<li><a></a></li>");
var $a = $li.find("a");
$a
.attr("href", "#" + $div[0].id)
.text(conf.l10n.issue + " " + report.number);
$a.attr("href", "#" + $div[0].id).text(
conf.l10n.issue + " " + report.number
);
if (report.title) {
$li.append(
$(
Expand Down
11 changes: 9 additions & 2 deletions src/core/structure.js
Expand Up @@ -42,13 +42,20 @@ function makeTOCAtLevel($parent, doc, current, level, conf) {
continue;
}
var title = h.textContent,
$kidsHolder = $("<div></div>").append($(h).contents().clone());
$kidsHolder = $("<div></div>").append(
$(h)
.contents()
.clone()
);
$kidsHolder
.find("a")
.renameElement("span")
.attr("class", "formerLink")
.removeAttr("href");
$kidsHolder.find("dfn").renameElement("span").removeAttr("id");
$kidsHolder
.find("dfn")
.renameElement("span")
.removeAttr("id");
var id = h.id ? h.id : $sec.makeID(null, title);

if (!isIntro) {
Expand Down
17 changes: 10 additions & 7 deletions src/core/utils.js
Expand Up @@ -12,9 +12,9 @@ marked.setOptions({
gfm: true,
});

const spaceOrTab = /^[\ |\t]*/;
const spaceOrTab = /^[ |\t]*/;
const endsWithSpace = /\s+$/gm;
const dashes = /\-/g;
const dashes = /-/g;
const gtEntity = /&gt;/gm;
const ampEntity = /&amp;/gm;

Expand Down Expand Up @@ -232,10 +232,10 @@ export function normalizePadding(text = "") {
doc.normalize();
// use the first space as an indicator of how much to chop off the front
const firstSpace = doc.body.innerText
.replace(/^\ *\n/, "")
.replace(/^ *\n/, "")
.split("\n")
.filter(item => item && item.startsWith(" "))[0];
var chop = firstSpace ? firstSpace.match(/\ +/)[0].length : 0;
var chop = firstSpace ? firstSpace.match(/ +/)[0].length : 0;
if (chop) {
// Chop chop from start, but leave pre elem alone
Array.from(doc.body.childNodes)
Expand All @@ -259,7 +259,7 @@ export function normalizePadding(text = "") {
const nextTo = prevSib
? prevSib.localName
: node.parentElement.localName;
if (/^[\t\ ]/.test(node.textContent) && inlineElems.has(nextTo)) {
if (/^[\t ]/.test(node.textContent) && inlineElems.has(nextTo)) {
padding = node.textContent.match(/^\s+/)[0];
}
node.textContent = padding + node.textContent.replace(replacer, "");
Expand Down Expand Up @@ -323,11 +323,12 @@ export function joinAnd(array = [], mapper = item => item) {
return items.toString();
case 2: // x and y
return items.join(" and ");
default:
default: {
// x, y, and z
const str = items.join(", ");
const lastComma = str.lastIndexOf(",");
return `${str.substr(0, lastComma + 1)} and ${str.slice(lastComma + 2)}`;
}
}
}

Expand Down Expand Up @@ -553,7 +554,9 @@ export function flatten(collector, item) {
Object(item)[Symbol.iterator] && typeof item.values === "function";
const items = !isObject
? [item]
: isIterable ? [...item.values()].reduce(flatten, []) : Object.values(item);
: isIterable
? [...item.values()].reduce(flatten, [])
: Object.values(item);
return [...collector, ...items];
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/webidl-clipboard.js
Expand Up @@ -19,8 +19,8 @@ const clipboardOps = {
text: trigger => {
return document
.querySelector(trigger.dataset.clipboardTarget)
.textContent.replace(/\ +/gm, " ")
.replace(/^\ /gm, " ")
.textContent.replace(/ +/gm, " ")
.replace(/^ /gm, " ")
.replace(/^};\n/gm, "};\n")
.trim();
},
Expand Down
2 changes: 1 addition & 1 deletion src/ui/dfn-list.js
Expand Up @@ -23,7 +23,7 @@ ul.addEventListener("click", ev => {
function show() {
const definitionLinks = Object.entries(respecConfig.definitionMap)
.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
.map(([key, $dfns]) => {
.map(([_key, $dfns]) => {
const [dfn] = $dfns[0];
return window.hyperHTML.wire(dfn, ":li>a")`
<li>
Expand Down
6 changes: 3 additions & 3 deletions src/ui/search-specref.js
Expand Up @@ -154,9 +154,9 @@ function render({ state, results, timeTaken, query } = { state: "" }) {
<p class="state" hidden="${!state}">
${state}
</p>
<section hidden="${!results}">${results
? renderResults(results, query, timeTaken)
: []}</section>
<section hidden="${!results}">${
results ? renderResults(results, query, timeTaken) : []
}</section>
`;
}

Expand Down
7 changes: 3 additions & 4 deletions src/w3c/headers.js
@@ -1,7 +1,6 @@
/*jshint
forin: false
*/
/*global hb*/

// Module w3c/headers
// Generate the headers material based on the provided configuration.
Expand Down Expand Up @@ -93,9 +92,7 @@
// - "w3c-software-doc", the W3C Software and Document License
// https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
import { concatDate, joinAnd, ISODate } from "core/utils";
import hb from "handlebars.runtime";
import { pub } from "core/pubsubhub";
import tmpls from "templates";
import cgbgSotdTmpl from "w3c/templates/cgbg-sotd";
import sotdTmpl from "w3c/templates/sotd";
import cgbgHeadersTmpl from "w3c/templates/cgbg-headers";
Expand Down Expand Up @@ -259,7 +256,9 @@ export function run(conf) {
const msg =
"Web Platform Tests have moved to a new Github Organization at https://github.com/web-platform-tests. " +
"Please update your [`testSuiteURI`](https://github.com/w3c/respec/wiki/testSuiteURI) to point to the " +
`new tests repository (e.g., https://github.com/web-platform-tests/${conf.shortName} ).`;
`new tests repository (e.g., https://github.com/web-platform-tests/${
conf.shortName
} ).`;
pub("warn", msg);
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/w3c/linter-rules/privsec-section.js
Expand Up @@ -23,13 +23,13 @@ const meta = {
const lang = defaultLang in meta ? defaultLang : "en";

function hasPriSecConsiderations(doc) {
return Array.from(
doc.querySelectorAll("h2, h3, h4, h5, h6")
).some(({ textContent: text }) => {
const saysPrivOrSec = /(privacy|security)/im.test(text);
const saysConsiderations = /(considerations)/im.test(text);
return (saysPrivOrSec && saysConsiderations) || saysPrivOrSec;
});
return Array.from(doc.querySelectorAll("h2, h3, h4, h5, h6")).some(
({ textContent: text }) => {
const saysPrivOrSec = /(privacy|security)/im.test(text);
const saysConsiderations = /(considerations)/im.test(text);
return (saysPrivOrSec && saysConsiderations) || saysPrivOrSec;
}
);
}

function lintingFunction(conf, doc) {
Expand Down
5 changes: 4 additions & 1 deletion src/w3c/permalinks.js
Expand Up @@ -25,7 +25,10 @@ export function run(conf, doc, cb) {
var symbol = conf.permalinkSymbol || "§";
var style = "<style>" + css(conf) + "</style>";

$(doc).find("head link").first().before(style);
$(doc)
.find("head link")
.first()
.before(style);
var $secs = $(doc).find("h2, h3, h4, h5, h6");
$secs.each(function(i, item) {
var $item = $(item);
Expand Down
6 changes: 3 additions & 3 deletions src/w3c/rfc2119.js
Expand Up @@ -26,9 +26,9 @@ export function run(conf, doc, cb) {
item => `<em class="rfc2119">${item}</em>`
);
const plural = terms.length > 1;
const str = `The key word${plural ? "s " : " "} ${html} ${plural
? "are"
: "is"} ${confo.innerHTML}`;
const str = `The key word${plural ? "s " : " "} ${html} ${
plural ? "are" : "is"
} ${confo.innerHTML}`;
confo.innerHTML = str;
cb();
}

0 comments on commit 273e51e

Please sign in to comment.