Skip to content

Commit

Permalink
Standardize styling for linters (#5030)
Browse files Browse the repository at this point in the history
* Standardize styling for linters

* Fix overuse of bolding

* Fix indentation of errors

* Undo changes to description tests (conflicts with #4872)
  • Loading branch information
queengooborg authored and Elchi3 committed Oct 29, 2019
1 parent 2e6530c commit a310b15
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 36 deletions.
8 changes: 4 additions & 4 deletions test/linter/test-browsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ function processData(data, displayBrowsers, requiredBrowsers, category, logger,

const invalidEntries = Object.keys(support).filter(value => !displayBrowsers.includes(value));
if (invalidEntries.length > 0) {
logger.error(chalk`{red {bold ${path}} has the following browsers, which are invalid for {bold ${category}} compat data: {bold ${invalidEntries.join(', ')}}}`);
logger.error(chalk`{red {bold ${path}} has the following browsers, which are invalid for {bold ${category}} compat data: {bold ${invalidEntries.join(', ')}}}`);
hasErrors = true;
}

const missingEntries = requiredBrowsers.filter(value => !(value in support));
if (missingEntries.length > 0) {
logger.error(chalk`{red {bold ${path}} is missing the following browsers, which are required for {bold ${category}} compat data: {bold ${missingEntries.join(', ')}}}`);
logger.error(chalk`{red {bold ${path}} is missing the following browsers, which are required for {bold ${category}} compat data: {bold ${missingEntries.join(', ')}}}`);
hasErrors = true;
}

Expand All @@ -77,7 +77,7 @@ function processData(data, displayBrowsers, requiredBrowsers, category, logger,
for (const statement of statementList) {
if (hasVersionAddedOnly(statement)) {
if (sawVersionAddedOnly) {
logger.error(`'${path}' has multiple support statement with only \`version_added\` for ${browser}`);
logger.error(chalk`{red → '{bold ${path}}' has multiple support statement with only \`{bold version_added}\` for {bold ${browser}}}`);
hasErrors = true;
break;
} else {
Expand Down Expand Up @@ -154,7 +154,7 @@ function testBrowsers(filename) {
if (errors.length) {
console.error(chalk`{red Browsers – {bold ${errors.length}} ${errors.length === 1 ? 'error' : 'errors'}:}`);
for (const error of errors) {
console.error(` ${error}`);
console.error(` ${error}`);
}
return true;
}
Expand Down
24 changes: 12 additions & 12 deletions test/linter/test-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function processData(filename, logger) {
match => {
// use https://bugzil.la/1000000 instead
hasErrors = true;
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Use shortenable URL ({yellow ${match[0]}} → {green {bold https://bugzil.la/}${match[1]}}).}`);
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Use shortenable URL ({yellow ${match[0]}} → {green {bold https://bugzil.la/}${match[1]}}).}`);
}
);

Expand All @@ -38,7 +38,7 @@ function processData(filename, logger) {
match => {
// use https://crbug.com/100000 instead
hasErrors = true;
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Use shortenable URL ({yellow ${match[0]}} → {green {bold https://crbug.com/}${match[1]}}).}`);
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Use shortenable URL ({yellow ${match[0]}} → {green {bold https://crbug.com/}${match[1]}}).}`);
}
);

Expand All @@ -47,7 +47,7 @@ function processData(filename, logger) {
match => {
// use https://webkit.org/b/100000 instead
hasErrors = true;
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Use shortenable URL ({yellow ${match[0]}} → {green {bold https://webkit.org/b/}${match[1]}}).}`);
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Use shortenable URL ({yellow ${match[0]}} → {green {bold https://webkit.org/b/}${match[1]}}).}`);
}
);

Expand All @@ -65,7 +65,7 @@ function processData(filename, logger) {

if (protocol !== 'https') {
hasErrors = true;
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Use HTTPS URL ({yellow http://${domain}/${bugId}} → {green http{bold s}://${domain}/${bugId}}).}`);
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Use HTTPS URL ({yellow http://${domain}/${bugId}} → {green http{bold s}://${domain}/${bugId}}).}`);
}

if (domain !== 'bugzil.la') {
Expand All @@ -74,15 +74,15 @@ function processData(filename, logger) {

if (/^bug $/.test(before)) {
hasErrors = true;
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Move word "bug" into link text ({yellow "${before}<a href='...'>${linkText}</a>"} → {green "<a href='...'>{bold ${before}}${bugId}</a>"}).}`);
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Move word "bug" into link text ({yellow "${before}<a href='...'>${linkText}</a>"} → {green "<a href='...'>{bold ${before}}${bugId}</a>"}).}`);
} else if (linkText === `Bug ${bugId}`) {
if (!/(\. |")$/.test(before)) {
hasErrors = true;
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Use lowercase "bug" word within sentence ({yellow "Bug ${bugId}"} → {green "{bold bug} ${bugId}"}).}`);
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Use lowercase "bug" word within sentence ({yellow "Bug ${bugId}"} → {green "{bold bug} ${bugId}"}).}`);
}
} else if (linkText !== `bug ${bugId}`) {
hasErrors = true;
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Use standard link text ({yellow "${linkText}"} → {green "bug ${bugId}"}).}`);
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Use standard link text ({yellow "${linkText}"} → {green "bug ${bugId}"}).}`);
}
}
)
Expand Down Expand Up @@ -121,21 +121,21 @@ function processData(filename, logger) {
if (protocol !== 'https') {
hasErrors = true;
logger.error(
chalk`{red ${pos} – Use HTTPS MDN URL ({yellow ${protocol}://developer.mozilla.org/${path}} → {green https://developer.mozilla.org/${expectedPath}}).}`,
chalk`{red ${pos} – Use HTTPS MDN URL ({yellow ${protocol}://developer.mozilla.org/${path}} → {green https://developer.mozilla.org/${expectedPath}}).}`,
);
}

if (subdomain) {
hasErrors = true;
logger.error(
chalk`{red ${pos} - Use correct MDN domain ({yellow ${protocol}://{red ${subdomain}}developer.mozilla.org/${path}} → {green https://developer.mozilla.org/${expectedPath}})}`,
chalk`{red ${pos} - Use correct MDN domain ({yellow ${protocol}://{red ${subdomain}}developer.mozilla.org/${path}} → {green https://developer.mozilla.org/${expectedPath}})}`,
);
}

if (path !== expectedPath) {
hasErrors = true;
logger.error(
chalk`{red ${pos} – Use ${
chalk`{red ${pos} – Use ${
locale ? 'non-localized' : 'correct'
} MDN URL ({yellow ${url}} → {green https://developer.mozilla.org/${expectedPath}}).}`,
);
Expand All @@ -147,7 +147,7 @@ function processData(filename, logger) {
String.raw`https?://developer.microsoft.com/(\w\w-\w\w)/(.*?)(?=["'\s])`,
match => {
hasErrors = true;
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Use non-localized Microsoft Developer URL ({yellow ${match[0]}} → {green https://developer.microsoft.com/${match[2]}}).}`);
logger.error(chalk`{red ${indexToPos(actual, match.index)} – Use non-localized Microsoft Developer URL ({yellow ${match[0]}} → {green https://developer.microsoft.com/${match[2]}}).}`);
}
);

Expand Down Expand Up @@ -186,7 +186,7 @@ function testLinks(filename) {
if (errors.length) {
console.error(chalk`{red Links – {bold ${errors.length}} ${errors.length === 1 ? 'error' : 'errors'}:}`);
for (const error of errors) {
console.error(` ${error}`);
console.error(` ${error}`);
}
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions test/linter/test-prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function checkPrefix(data, category, errors, prefix, path="") {
for (const key in data) {
if (key === "prefix" && typeof(data[key]) === "string") {
if (data[key].includes(prefix)) {
const error = chalk`{red {bold ${prefix}} prefix is wrong for key: {bold ${path}}}`;
const error = chalk`{red {bold ${prefix}} prefix is wrong for key: {bold ${path}}}`;
const rules = [
category == "api" && !data[key].startsWith(prefix),
category == "css" && !data[key].startsWith(`-${prefix}`)
Expand Down Expand Up @@ -51,7 +51,7 @@ function testPrefix(filename) {
if (errors.length) {
console.error(chalk`{red Prefix – {bold ${errors.length}} ${errors.length === 1 ? 'error' : 'errors'}:}`);
for (const error of errors) {
console.error(` ${error}`);
console.error(` ${error}`);
}
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions test/linter/test-real-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ function checkRealValues(supportData, blockList, relPath, logger) {

for (const statement of supportStatements) {
if (statement === undefined) {
logger.error(chalk`{red {bold ${browser}} must be defined for {bold ${relPath}}}`);
logger.error(chalk`{red {bold ${browser}} must be defined for {bold ${relPath}}}`);
hasErrors = true;
} else {
if ([true, null].includes(statement.version_added)) {
logger.error(chalk`{red {bold ${relPath}} - {bold ${browser}} no longer accepts {bold ${statement.version_added}} as a value}`);
logger.error(chalk`{red {bold ${relPath}} - {bold ${browser}} no longer accepts {bold ${statement.version_added}} as a value}`);
hasErrors = true;
}
if ([true, null].includes(statement.version_removed)) {
logger.error(chalk`{red {bold ${relPath}} - {bold ${browser}} no longer accepts} {bold ${statement.version_removed}} as a value}`);
logger.error(chalk`{red {bold ${relPath}} - {bold ${browser}} no longer accepts} {bold ${statement.version_removed}} as a value}`);
hasErrors = true;
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ function testRealValues(filename) {
if (errors.length) {
console.error(chalk`{red Real values – {bold ${errors.length}} ${errors.length === 1 ? 'error' : 'errors'}:}`);
for (const error of errors) {
console.error(` ${error}`);
console.error(` ${error}`);
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion test/linter/test-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function testSchema(dataFilename, schemaFilename = './../../schemas/compat-data.
const valid = ajv.validate(schema, data);

if (!valid) {
console.error(chalk`{red {bold JSON Schema} – {bold ${ajv.errors.length}} ${ajv.errors.length === 1 ? 'error' : 'errors'}:}`);
console.error(chalk`{red JSON Schema – {bold ${ajv.errors.length}} ${ajv.errors.length === 1 ? 'error' : 'errors'}:}`);
// Output messages by one since better-ajv-errors wrongly joins messages
// (see https://github.com/atlassian/better-ajv-errors/pull/21)
ajv.errors.forEach(e => {
Expand Down
14 changes: 7 additions & 7 deletions test/linter/test-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,29 @@ function processData(filename, logger) {

if (actual !== expected) {
hasErrors = true;
logger.error(chalk`{red Error on ${jsonDiff(actual, expected)}}`);
logger.error(chalk`{red Error on ${jsonDiff(actual, expected)}}`);
}

if (expected !== expectedBrowserSorting) {
hasErrors = true;
logger.error(chalk`{red Browser sorting error on ${jsonDiff(actual, expectedBrowserSorting)}}\n{blue Tip: Run {bold npm run fix} to fix sorting automatically}`);
logger.error(chalk`{red Browser sorting error on ${jsonDiff(actual, expectedBrowserSorting)}}\n{blue Tip: Run {bold npm run fix} to fix sorting automatically}`);
}

if (expected !== expectedFeatureSorting) {
hasErrors = true;
logger.error(chalk`{red Feature sorting error on ${jsonDiff(actual, expectedFeatureSorting)}}\n{blue Tip: Run {bold npm run fix} to fix sorting automatically}`);
logger.error(chalk`{red Feature sorting error on ${jsonDiff(actual, expectedFeatureSorting)}}\n{blue Tip: Run {bold npm run fix} to fix sorting automatically}`);
}

const constructorMatch = actual.match(String.raw`"<code>([^)]*?)</code> constructor"`)
if (constructorMatch) {
hasErrors = true;
logger.error(chalk`{red ${indexToPos(actual, constructorMatch.index)} – Use parentheses in constructor description ({yellow ${constructorMatch[1]}} → {green ${constructorMatch[1]}{bold ()}}).}`);
logger.error(chalk`{red ${indexToPos(actual, constructorMatch.index)} – Use parentheses in constructor description ({yellow ${constructorMatch[1]}} → {green ${constructorMatch[1]}{bold ()}}).}`);
}

const hrefDoubleQuoteIndex = actual.indexOf('href=\\"');
if (hrefDoubleQuoteIndex >= 0) {
hasErrors = true;
logger.error(chalk`{red ${indexToPos(actual, hrefDoubleQuoteIndex)} - Found {yellow \\"}, but expected {green \'} for <a href>.}`);
logger.error(chalk`{red ${indexToPos(actual, hrefDoubleQuoteIndex)} - Found {yellow \\"}, but expected {green \'} for <a href>.}`);
}

const regexp = new RegExp(String.raw`<a href='([^'>]+)'>((?:.(?!</a>))*.)</a>`, 'g');
Expand All @@ -104,7 +104,7 @@ function processData(filename, logger) {
const a_url = url.parse(match[1]);
if (a_url.hostname === null) {
hasErrors = true;
logger.error(chalk`{red ${indexToPos(actual, constructorMatch.index)} - Include hostname in URL ({yellow ${match[1]}} → {green {bold https://developer.mozilla.org/}${match[1]}}).}`);
logger.error(chalk`{red ${indexToPos(actual, constructorMatch.index)} - Include hostname in URL ({yellow ${match[1]}} → {green {bold https://developer.mozilla.org/}${match[1]}}).}`);
}
}

Expand All @@ -126,7 +126,7 @@ function testStyle(filename) {
if (errors.length) {
console.error(chalk`{red Style – {bold ${errors.length}} ${errors.length === 1 ? 'error' : 'errors'}:}`);
for (const error of errors) {
console.error(` ${error}`);
console.error(` ${error}`);
}
return true;
}
Expand Down
10 changes: 5 additions & 5 deletions test/linter/test-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ function checkVersions(supportData, relPath, logger) {

for (const statement of supportStatements) {
if (!isValidVersion(browser, statement.version_added)) {
logger.error(chalk`{red {bold ${relPath}} - {bold version_added: "${statement.version_added}"} is {bold NOT} a valid version number for {bold ${browser}}\n Valid {bold ${browser}} versions are: ${validBrowserVersionsString}}`);
logger.error(chalk`{red {bold ${relPath}} - {bold version_added: "${statement.version_added}"} is {bold NOT} a valid version number for {bold ${browser}}\n Valid {bold ${browser}} versions are: ${validBrowserVersionsString}}`);
hasErrors = true;
}
if (!isValidVersion(browser, statement.version_removed)) {
logger.error(chalk`{red {bold ${relPath}} - {bold version_removed: "${statement.version_removed}"} is {bold NOT} a valid version number for {bold ${browser}}\n Valid {bold ${browser}} versions are: ${validBrowserVersionsString}}`);
logger.error(chalk`{red {bold ${relPath}} - {bold version_removed: "${statement.version_removed}"} is {bold NOT} a valid version number for {bold ${browser}}\n Valid {bold ${browser}} versions are: ${validBrowserVersionsString}}`);
hasErrors = true;
}
if ('version_removed' in statement && 'version_added' in statement) {
if (
typeof statement.version_added !== 'string' &&
statement.version_added !== true
) {
logger.error(chalk`{red {bold ${relPath}} - {bold version_added: "${statement.version_added}"} is {bold NOT} a valid version number for {bold ${browser}} when {bold version_removed} is present\n Valid {bold ${browser}} versions are: ${validBrowserVersionsTruthy}}`);
logger.error(chalk`{red {bold ${relPath}} - {bold version_added: "${statement.version_added}"} is {bold NOT} a valid version number for {bold ${browser}} when {bold version_removed} is present\n Valid {bold ${browser}} versions are: ${validBrowserVersionsTruthy}}`);
hasErrors = true;
} else if (typeof statement.version_added === 'string' && typeof statement.version_removed === 'string') {
if (
Expand All @@ -84,7 +84,7 @@ function checkVersions(supportData, relPath, logger) {
compareVersions.compare(statement.version_added.replace("≤", ""), statement.version_removed.replace("≤", ""), ">=")
)
) {
logger.error(chalk`{red {bold ${relPath}} - {bold version_removed: "${statement.version_removed}"} must be greater than {bold version_added: "${statement.version_added}"}}`);
logger.error(chalk`{red {bold ${relPath}} - {bold version_removed: "${statement.version_removed}"} must be greater than {bold version_added: "${statement.version_added}"}}`);
hasErrors = true;
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ function testVersions(filename) {
if (errors.length) {
console.error(chalk`{red Versions – {bold ${errors.length}} ${errors.length === 1 ? 'error' : 'errors'}:}`);
for (const error of errors) {
console.error(` ${error}`);
console.error(` ${error}`);
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion test/test-compare-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const testFeatureOrder = () => {

if (errors) {
console.error(chalk`{red compareFeatures() – {bold 1} error:}`);
console.error(chalk`{red Actual and expected orders do not match}`);
console.error(chalk`{red Actual and expected orders do not match}`);
console.error(chalk`{yellow Actual: {bold ${actual}}}`);
console.error(chalk`{green Expected: {bold ${expected}}}`);
return true;
Expand Down

0 comments on commit a310b15

Please sign in to comment.