Browse Source

chore: update prettier, style changes (#2800)

* style: prettier arrowParens: avoid
* style: inline many html template tags

Co-authored-by: greenkeeper[bot] <23040076+greenkeeper[bot]@users.noreply.github.com>
pull/2802/head
Sid Vishnoi 3 years ago committed by GitHub
parent
commit
5a3c14de89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      karma.conf.js
  2. 6
      package-lock.json
  3. 5
      package.json
  4. 5
      src/core/dfn-finder.js
  5. 4
      src/core/examples.js
  6. 2
      src/core/expose-modules.js
  7. 12
      src/core/jquery-enhanced.js
  8. 7
      src/core/linter-rules/check-charset.js
  9. 5
      src/dini/conformance.js
  10. 2
      src/dini/headers.js
  11. 4
      src/dini/templates/headers.js
  12. 4
      src/dini/templates/show-link.js
  13. 4
      src/dini/templates/show-logo.js
  14. 50
      src/dini/templates/show-people.js
  15. 5
      src/w3c/conformance.js
  16. 2
      src/w3c/headers.js
  17. 10
      src/w3c/templates/cgbg-headers.js
  18. 12
      src/w3c/templates/headers.js
  19. 4
      src/w3c/templates/show-link.js
  20. 4
      src/w3c/templates/show-logo.js
  21. 46
      src/w3c/templates/show-people.js
  22. 8
      src/w3c/templates/sotd.js
  23. 2
      tests/support-files/hljs-testlang.js
  24. 2
      tests/test-main.js
  25. 8
      tools/respecDocWriter.js

2
karma.conf.js

@ -1,7 +1,7 @@
// Karma configuration
// Generated on Fri Feb 26 2016 13:09:51 GMT+1100 (AEDT)
"use strict";
module.exports = function(config) {
module.exports = function (config) {
const options = {
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: "./",

6
package-lock.json generated

@ -5041,9 +5041,9 @@
"integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw="
},
"prettier": {
"version": "1.19.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz",
"integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.1.tgz",
"integrity": "sha512-piXGBcY1zoFOG0MvHpNE5reAGseLmaCRifQ/fmfF49BcYkInEs/naD/unxGNAeOKFA5+JxVrPyMvMlpzcd20UA==",
"dev": true
},
"prettier-linter-helpers": {

5
package.json

@ -58,7 +58,7 @@
"mocha": "^7.1.1",
"moment": "^2.24.0",
"pluralize": "^8.0.0",
"prettier": "^1.19.1",
"prettier": "^2.0.1",
"rollup": "^2.0.2",
"rollup-plugin-alias": "^2.2.0",
"rollup-plugin-commonjs": "^10.1.0",
@ -105,7 +105,8 @@
"snyk": "^1.297.1"
},
"prettier": {
"trailingComma": "es5"
"trailingComma": "es5",
"arrowParens": "avoid"
},
"snyk": true,
"collective": {

5
src/core/dfn-finder.js

@ -182,10 +182,7 @@ export function decorateDfn(dfnElem, idlAst, parent, name) {
if (!dfnElem.id) {
const lCaseParent = parent.toLowerCase();
const middle = lCaseParent ? `${lCaseParent}-` : "";
let last = name
.toLowerCase()
.replace(/[()]/g, "")
.replace(/\s/g, "-");
let last = name.toLowerCase().replace(/[()]/g, "").replace(/\s/g, "-");
if (last === "") last = "the-empty-string";
dfnElem.id = `dom-${middle}${last}`;
}

4
src/core/examples.js

@ -62,9 +62,7 @@ function makeTitle(elem, num, report) {
if (report.title) elem.removeAttribute("title");
const number = num > 0 ? ` ${num}` : "";
const title = report.title
? html`
<span class="example-title">: ${report.title}</span>
`
? html` <span class="example-title">: ${report.title}</span> `
: "";
return html`
<div class="marker">

2
src/core/expose-modules.js

@ -6,7 +6,7 @@ if (!inAmd) {
* @param {string[]} deps
* @param {(...modules: any[]) => void} callback
*/
const require = function(deps, callback) {
const require = function (deps, callback) {
const modules = deps.map(dep => {
if (!(dep in window.require.modules)) {
throw new Error(`Unsupported dependency name: ${dep}`);

12
src/core/jquery-enhanced.js vendored

@ -15,10 +15,10 @@ window.$ = window.jQuery = $;
// --- JQUERY EXTRAS -----------------------------------------------------------------------
// Applies to any jQuery object containing elements, changes their name to the one give, and
// return a jQuery object containing the new elements
window.$.fn.renameElement = function(name) {
window.$.fn.renameElement = function (name) {
const arr = [];
// @ts-ignore
this.each(function() {
this.each(function () {
// @ts-ignore
const elem = this;
const newElem = renameElement(elem, name);
@ -41,7 +41,7 @@ window.$.fn.renameElement = function(name) {
//
// This method will publish a warning if a title is used on a definition
// instead of an @lt (as per specprod mailing list discussion).
window.$.fn.getDfnTitles = function() {
window.$.fn.getDfnTitles = function () {
return getDfnTitles(this[0]);
};
@ -55,19 +55,19 @@ window.$.fn.getDfnTitles = function() {
// * {for: "int2", title: "int3.member"}
// * {for: "int3", title: "member"}
// * {for: "", title: "int3.member"}
window.$.fn.linkTargets = function() {
window.$.fn.linkTargets = function () {
return getLinkTargets(this[0]);
};
// Applied to an element, sets an ID for it (and returns it), using a specific prefix
// if provided, and a specific text if given.
window.$.fn.makeID = function(pfx = "", txt = "", noLC = false) {
window.$.fn.makeID = function (pfx = "", txt = "", noLC = false) {
const elem = this[0];
return addId(elem, pfx, txt, noLC);
};
// Returns all the descendant text nodes of an element. Note that those nodes aren't
// returned as a jQuery array since I'm not sure if that would make too much sense.
window.$.fn.allTextNodes = function(exclusions) {
window.$.fn.allTextNodes = function (exclusions) {
return getTextNodes(this[0], exclusions);
};

7
src/core/linter-rules/check-charset.js

@ -28,12 +28,7 @@ function linterFunction(_, doc) {
const metas = doc.querySelectorAll("meta[charset]");
const val = [];
for (const meta of metas) {
val.push(
meta
.getAttribute("charset")
.trim()
.toLowerCase()
);
val.push(meta.getAttribute("charset").trim().toLowerCase());
}
const utfExists = val.includes("utf-8");

5
src/dini/conformance.js

@ -68,10 +68,7 @@ function processConformance(conformance, conf) {
// Put in the 2119 clause and reference
const keywords = htmlJoinAnd(
terms.sort(),
item =>
html`
<em class="rfc2119">${item}</em>
`
item => html` <em class="rfc2119">${item}</em> `
);
const plural = terms.length > 1;
const content = html`

2
src/dini/headers.js

@ -94,7 +94,7 @@ export function run(conf) {
);
conf.publishYear = conf.publishDate.getUTCFullYear();
conf.publishHumanDate = DINIDate.format(conf.publishDate);
const peopCheck = function(it) {
const peopCheck = function (it) {
if (!it.name) pub("error", "All authors and editors must have a name.");
if (it.orcid) {
try {

4
src/dini/templates/headers.js

@ -147,9 +147,7 @@ export default conf => {
* @param {string=} cssClass
*/
function linkLicense(text, url, cssClass) {
return html`
<a rel="license" href="${url}" class="${cssClass}">${text}</a>
`;
return html` <a rel="license" href="${url}" class="${cssClass}">${text}</a> `;
}
function renderCopyright(conf) {

4
src/dini/templates/show-link.js

@ -21,9 +21,7 @@ function showLinkData(data) {
return html`
<dd class="${data.class ? data.class : null}">
${data.href
? html`
<a href="${data.href}">${data.value || data.href}</a>
`
? html` <a href="${data.href}">${data.value || data.href}</a> `
: ""}
</dd>
`;

4
src/dini/templates/show-logo.js

@ -4,9 +4,7 @@ import { showInlineWarning } from "../../core/utils.js";
export default obj => {
/** @type {HTMLAnchorElement} */
const a = html`
<a href="${obj.url || ""}" class="logo"></a>
`;
const a = html` <a href="${obj.url || ""}" class="logo"></a> `;
if (!obj.alt) {
showInlineWarning(a, "Found spec logo without an `alt` attribute");
}

50
src/dini/templates/show-people.js

@ -10,37 +10,27 @@ import { hyperHTML as html } from "../../core/import-maps.js";
const localizationStrings = {
en: {
until(date) {
return html`
Until ${date}
`;
return html` Until ${date} `;
},
},
es: {
until(date) {
return html`
Hasta ${date}
`;
return html` Hasta ${date} `;
},
},
ko: {
until(date) {
return html`
${date} 이전
`;
return html` ${date} 이전 `;
},
},
ja: {
until(date) {
return html`
${date} 以前
`;
return html` ${date} 以前 `;
},
},
de: {
until(date) {
return html`
bis ${date}
`;
return html` bis ${date} `;
},
},
};
@ -55,9 +45,7 @@ export default (items = []) => {
const personName = [p.name]; // treated as opt-in HTML by hyperHTML
const company = [p.company];
/** @type {HTMLElement} */
const dd = html`
<dd class="p-author h-card vcard"></dd>
`;
const dd = html` <dd class="p-author h-card vcard"></dd> `;
const span = document.createDocumentFragment();
const contents = [];
if (p.mailto) {
@ -71,11 +59,7 @@ export default (items = []) => {
<a class="u-url url p-name fn" href="${p.url}">${personName}</a>
`);
} else {
contents.push(
html`
<span class="p-name fn">${personName}</span>
`
);
contents.push(html` <span class="p-name fn">${personName}</span> `);
}
if (p.orcid) {
contents.push(
@ -115,11 +99,7 @@ export default (items = []) => {
`
);
} else {
contents.push(
html`
(${company})
`
);
contents.push(html` (${company}) `);
}
}
if (p.note) contents.push(document.createTextNode(` (${p.note})`));
@ -148,11 +128,7 @@ export default (items = []) => {
);
}
timeElem.dateTime = toShortIsoDate(retiredDate);
contents.push(
html`
- ${l10n.until(timeElem)}
`
);
contents.push(html` - ${l10n.until(timeElem)} `);
}
// @ts-ignore: hyperhtml types only support Element but we use a DocumentFragment here
@ -162,14 +138,10 @@ export default (items = []) => {
}
function getExtra(extra) {
const span = html`
<span class="${extra.class || null}"></span>
`;
const span = html` <span class="${extra.class || null}"></span> `;
let textContainer = span;
if (extra.href) {
textContainer = html`
<a href="${extra.href}"></a>
`;
textContainer = html` <a href="${extra.href}"></a> `;
span.appendChild(textContainer);
}
textContainer.textContent = extra.name;

5
src/w3c/conformance.js

@ -68,10 +68,7 @@ function processConformance(conformance, conf) {
// Put in the 2119 clause and reference
const keywords = htmlJoinAnd(
terms.sort(),
item =>
html`
<em class="rfc2119">${item}</em>
`
item => html` <em class="rfc2119">${item}</em> `
);
const plural = terms.length > 1;
const content = html`

2
src/w3c/headers.js

@ -370,7 +370,7 @@ export function run(conf) {
}
if (conf.prevRecShortname && !conf.prevRecURI)
conf.prevRecURI = `https://www.w3.org/TR/${conf.prevRecShortname}`;
const peopCheck = function(it) {
const peopCheck = function (it) {
if (!it.name) pub("error", "All authors and editors must have a name.");
if (it.orcid) {
try {

10
src/w3c/templates/cgbg-headers.js

@ -17,11 +17,7 @@ export default (conf, options) => {
return html`
<div class="head">
${conf.logos.map(showLogo)} ${specTitleElem}
${conf.subtitle
? html`
<h2 id="subtitle">${conf.subtitle}</h2>
`
: ""}
${conf.subtitle ? html` <h2 id="subtitle">${conf.subtitle}</h2> ` : ""}
<h2>
${conf.longStatus}
<time class="dt-published" datetime="${conf.dashDate}"
@ -129,9 +125,7 @@ export default (conf, options) => {
? `${conf.copyrightStart}-`
: ""}${conf.publishYear}
${conf.additionalCopyrightHolders
? html`
${[conf.additionalCopyrightHolders]} &amp;
`
? html` ${[conf.additionalCopyrightHolders]} &amp; `
: ""}
the Contributors to the ${specTitleElemClone.childNodes}
Specification, published by the

12
src/w3c/templates/headers.js

@ -246,9 +246,7 @@ export default (conf, options) => {
* @param {string=} cssClass
*/
function linkLicense(text, url, cssClass) {
return html`
<a rel="license" href="${url}" class="${cssClass}">${text}</a>
`;
return html` <a rel="license" href="${url}" class="${cssClass}">${text}</a> `;
}
function renderCopyright(conf) {
@ -266,9 +264,7 @@ function renderCopyright(conf) {
}
return conf.isUnofficial
? conf.additionalCopyrightHolders
? html`
<p class="copyright">${[conf.additionalCopyrightHolders]}</p>
`
? html` <p class="copyright">${[conf.additionalCopyrightHolders]}</p> `
: conf.overrideCopyright
? [conf.overrideCopyright]
: html`
@ -295,9 +291,7 @@ function renderOfficialCopyright(conf) {
&copy;
${conf.copyrightStart ? `${conf.copyrightStart}-` : ""}${conf.publishYear}
${conf.additionalCopyrightHolders
? html`
${[conf.additionalCopyrightHolders]} &amp;
`
? html` ${[conf.additionalCopyrightHolders]} &amp; `
: ""}
<a href="https://www.w3.org/"
><abbr title="World Wide Web Consortium">W3C</abbr></a

4
src/w3c/templates/show-link.js

@ -21,9 +21,7 @@ function showLinkData(data) {
return html`
<dd class="${data.class ? data.class : null}">
${data.href
? html`
<a href="${data.href}">${data.value || data.href}</a>
`
? html` <a href="${data.href}">${data.value || data.href}</a> `
: data.value}
</dd>
`;

4
src/w3c/templates/show-logo.js

@ -4,9 +4,7 @@ import { showInlineWarning } from "../../core/utils.js";
export default obj => {
/** @type {HTMLAnchorElement} */
const a = html`
<a href="${obj.url || ""}" class="logo"></a>
`;
const a = html` <a href="${obj.url || ""}" class="logo"></a> `;
if (!obj.alt) {
showInlineWarning(a, "Found spec logo without an `alt` attribute");
}

46
src/w3c/templates/show-people.js

@ -10,37 +10,27 @@ import { hyperHTML as html } from "../../core/import-maps.js";
const localizationStrings = {
en: {
until(date) {
return html`
Until ${date}
`;
return html` Until ${date} `;
},
},
es: {
until(date) {
return html`
Hasta ${date}
`;
return html` Hasta ${date} `;
},
},
ko: {
until(date) {
return html`
${date} 이전
`;
return html` ${date} 이전 `;
},
},
ja: {
until(date) {
return html`
${date} 以前
`;
return html` ${date} 以前 `;
},
},
de: {
until(date) {
return html`
bis ${date}
`;
return html` bis ${date} `;
},
},
};
@ -72,11 +62,7 @@ export default (items = []) => {
<a class="u-url url p-name fn" href="${p.url}">${personName}</a>
`);
} else {
contents.push(
html`
<span class="p-name fn">${personName}</span>
`
);
contents.push(html` <span class="p-name fn">${personName}</span> `);
}
if (p.orcid) {
contents.push(
@ -116,11 +102,7 @@ export default (items = []) => {
`
);
} else {
contents.push(
html`
(${company})
`
);
contents.push(html` (${company}) `);
}
}
if (p.note) contents.push(document.createTextNode(` (${p.note})`));
@ -149,11 +131,7 @@ export default (items = []) => {
);
}
timeElem.dateTime = toShortIsoDate(retiredDate);
contents.push(
html`
- ${l10n.until(timeElem)}
`
);
contents.push(html` - ${l10n.until(timeElem)} `);
}
// @ts-ignore: hyperhtml types only support Element but we use a DocumentFragment here
@ -163,14 +141,10 @@ export default (items = []) => {
}
function getExtra(extra) {
const span = html`
<span class="${extra.class || null}"></span>
`;
const span = html` <span class="${extra.class || null}"></span> `;
let textContainer = span;
if (extra.href) {
textContainer = html`
<a href="${extra.href}"></a>
`;
textContainer = html` <a href="${extra.href}"></a> `;
span.appendChild(textContainer);
}
textContainer.textContent = extra.name;

8
src/w3c/templates/sotd.js

@ -122,9 +122,7 @@ export default (conf, opts) => {
>.
</p>
${conf.addPatentNote
? html`
<p>${[conf.addPatentNote]}</p>
`
? html` <p>${[conf.addPatentNote]}</p> `
: ""}
`}
`}
@ -250,9 +248,7 @@ function renderDeliverer(conf) {
${!isNote && !isIGNote
? html`
${multipleWGs
? html`
W3C maintains ${wgPatentHTML}
`
? html` W3C maintains ${wgPatentHTML} `
: html`
W3C maintains a
<a href="${[wgPatentURI]}" rel="disclosure"

2
tests/support-files/hljs-testlang.js

@ -7,7 +7,7 @@ function testLang() {
};
}
module.exports = function(hljs) {
module.exports = function (hljs) {
hljs.registerLanguage("funkytest", testLang);
};

2
tests/test-main.js

@ -7,7 +7,7 @@ const testFiles = Object.keys(window.__karma__.files)
// Allows tests to be loaded asynchronously
// TODO: Remove this when browsers add support for top level await
window.__karma__.loaded = function() {};
window.__karma__.loaded = function () {};
// Note that import() here is a special ES syntax
// so it cannot be used as .map(import);

8
tools/respecDocWriter.js

@ -125,11 +125,11 @@ async function generateHTML(page, url) {
return await page.evaluate(evaluateHTML, version);
} catch (err) {
const msg = `\n😭 Sorry, there was an error generating the HTML. Please report this issue!\n${colors.debug(
`${`Specification: ${url}\n` +
`${
`Specification: ${url}\n` +
`ReSpec version: ${version.join(".")}\n` +
"File a bug: https://github.com/w3c/respec/\n"}${
err ? `Error: ${err.stack}\n` : ""
}`
"File a bug: https://github.com/w3c/respec/\n"
}${err ? `Error: ${err.stack}\n` : ""}`
)}`;
throw new Error(msg);
}

Loading…
Cancel
Save