Skip to content

Commit

Permalink
Add test for WD and FPWD regarding shortname (#1648)
Browse files Browse the repository at this point in the history
* remove unused variable, resolves #1646

* add test for WD and FPWD regarding shortname

* Update lib/l10n-en_GB.js

Co-authored-by: Denis Ah-Kang <[email protected]>

* Update lib/l10n-en_GB.js

Co-authored-by: Denis Ah-Kang <[email protected]>

* chore(deps): bump puppeteer from 18.0.5 to 18.2.1

Bumps [puppeteer](https://github.com/puppeteer/puppeteer) from 18.0.5 to 18.2.1.
- [Release notes](https://github.com/puppeteer/puppeteer/releases)
- [Changelog](https://github.com/puppeteer/puppeteer/blob/main/release-please-config.json)
- [Commits](puppeteer/puppeteer@v18.0.5...puppeteer-core-v18.2.1)

---
updated-dependencies:
- dependency-name: puppeteer
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps-dev): bump eslint from 8.24.0 to 8.25.0

Bumps [eslint](https://github.com/eslint/eslint) from 8.24.0 to 8.25.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](eslint/eslint@v8.24.0...v8.25.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* move shortname check to dl.js

* improve function isFP(), resolves #1647

* fix test

* remove Supersedes and Obsoletes check

* fix test

* fix test

* fix test

* chore(deps-dev): bump mocha from 10.0.0 to 10.1.0

Bumps [mocha](https://github.com/mochajs/mocha) from 10.0.0 to 10.1.0.
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
- [Commits](mochajs/mocha@v10.0.0...v10.1.0)

---
updated-dependencies:
- dependency-name: mocha
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps): bump puppeteer from 18.2.1 to 19.0.0

Bumps [puppeteer](https://github.com/puppeteer/puppeteer) from 18.2.1 to 19.0.0.
- [Release notes](https://github.com/puppeteer/puppeteer/releases)
- [Changelog](https://github.com/puppeteer/puppeteer/blob/main/release-please-config.json)
- [Commits](puppeteer/puppeteer@puppeteer-core-v18.2.1...puppeteer-core-v19.0.0)

---
updated-dependencies:
- dependency-name: puppeteer
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update lib/validator.js

Co-authored-by: Denis Ah-Kang <[email protected]>

* Update lib/rules/headers/w3c-state.js

* chore(deps): bump puppeteer from 19.0.0 to 19.1.0

Bumps [puppeteer](https://github.com/puppeteer/puppeteer) from 19.0.0 to 19.1.0.
- [Release notes](https://github.com/puppeteer/puppeteer/releases)
- [Changelog](https://github.com/puppeteer/puppeteer/blob/main/release-please-config.json)
- [Commits](puppeteer/puppeteer@puppeteer-core-v19.0.0...puppeteer-core-v19.1.0)

---
updated-dependencies:
- dependency-name: puppeteer
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps-dev): bump eslint from 8.25.0 to 8.26.0

Bumps [eslint](https://github.com/eslint/eslint) from 8.25.0 to 8.26.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](eslint/eslint@v8.25.0...v8.26.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* apply suggestion

* chore(deps): bump puppeteer from 19.1.0 to 19.2.0

Bumps [puppeteer](https://github.com/puppeteer/puppeteer) from 19.1.0 to 19.2.0.
- [Release notes](https://github.com/puppeteer/puppeteer/releases)
- [Changelog](https://github.com/puppeteer/puppeteer/blob/main/release-please-config.json)
- [Commits](puppeteer/puppeteer@puppeteer-core-v19.1.0...puppeteer-core-v19.2.0)

---
updated-dependencies:
- dependency-name: puppeteer
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps): bump promise from 8.2.0 to 8.3.0

Bumps [promise](https://github.com/then/promise) from 8.2.0 to 8.3.0.
- [Release notes](https://github.com/then/promise/releases)
- [Commits](then/promise@8.2.0...8.3.0)

---
updated-dependencies:
- dependency-name: promise
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps-dev): bump eslint-plugin-jsdoc from 39.3.2 to 39.4.0

Bumps [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) from 39.3.2 to 39.4.0.
- [Release notes](https://github.com/gajus/eslint-plugin-jsdoc/releases)
- [Commits](gajus/eslint-plugin-jsdoc@v39.3.2...v39.4.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-jsdoc
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* move error msg in l10n-en_GB

* move shortname check to shortname.js

* fix test

* fix nock charter date, fix test

* Add more date format (#1664)

* add date formats

* fix test

* Update lib/rules.json

Co-authored-by: Denis Ah-Kang <[email protected]>

Co-authored-by: Denis Ah-Kang <[email protected]>

* remove unused variable, resolves #1646

* add test for WD and FPWD regarding shortname

* Update lib/l10n-en_GB.js

Co-authored-by: Denis Ah-Kang <[email protected]>

* Update lib/l10n-en_GB.js

Co-authored-by: Denis Ah-Kang <[email protected]>

* move shortname check to dl.js

* improve function isFP(), resolves #1647

* fix test

* remove Supersedes and Obsoletes check

* fix test

* fix test

* fix test

* Update lib/validator.js

Co-authored-by: Denis Ah-Kang <[email protected]>

* Update lib/rules/headers/w3c-state.js

* apply suggestion

* move error msg in l10n-en_GB

* move shortname check to shortname.js

* fix test

* fix nock charter date, fix test

* fix test

* fix test

* fix test

* apply suggestion

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Denis Ah-Kang <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 7, 2022
1 parent 382fa7d commit 199e70f
Show file tree
Hide file tree
Showing 16 changed files with 395 additions and 700 deletions.
46 changes: 16 additions & 30 deletions lib/l10n-en_GB.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,24 @@ export const messages = {
'headers.h1-title.not-found': 'Cannot find title or h1 of the document.',
'headers.h1-title.not-match':
"Content of title and h1 do not match. Text of title is '${titleText}' while h1 is (transformed into) '${h1Text}'.",
// headers/shortname
'headers.shortname.shortname-lowercase':
'The shortname of the document must in lowercase, but `${shortname}` is found.',
'headers.shortname.this-latest-shortname':
'<em>Shortnames</em> differ between This version (${thisShortname}) and Latest Versions (${latestShortname}).',
'headers.shortname.this-previous-shortname':
'<em>Shortnames</em> differ between This version (${thisShortname}) and Previous Versions (${previousShortname}).',
'headers.shortname.history-syntax':
'Wrong syntax for History link, please use the link "https://www.w3.org/standards/history/${shortname}".',
'headers.shortname.history-bad-previous':
'This document contains a shortname change with previous shortname "${previousShortname}", but the it seems be not correct because "${url}" doesn\'t exist.',
'headers.shortname.this-rescinds-shortname':
'<em>Shortnames</em> differ between This Version (${thisShortname}) and Rescinds this Recommendation (${rescindsShortname}).',
'headers.shortname.shortname-existed': 'FPWDs must use a new shortname',
'headers.shortname.shortname-not-existed':
'The ${status} should use an existing shortname.',
// headers/dl
'headers.dl.this-version': 'This Version is missing.',
'headers.dl.shortname-lowercase':
'The shortname of the document must in lowercase, but `${shortname}` is found.',
'headers.dl.latest-version': 'Latest Version is missing.',
'headers.dl.no-history': 'History link is missing.',
'headers.dl.this-latest-order':
Expand All @@ -69,42 +83,14 @@ export const messages = {
'Mismatch between document date and This Version link.',
'headers.dl.no-date': 'Cannot find document date.',
'headers.dl.this-syntax': 'Wrong syntax for This Version link.',
'headers.dl.this-latest-shortname':
'<em>Shortnames</em> differ between This version (${thisShortname}) and Latest Versions (${latestShortname}).',
'headers.dl.latest-syntax': 'Wrong syntax for Latest Version link.',
'headers.dl.this-previous-shortname':
'<em>Shortnames</em> differ between This version (${thisShortname}) and Previous Versions (${previousShortname}).',
'headers.dl.history-syntax':
'Wrong syntax for History link, please use the link "https://www.w3.org/standards/history/${shortname}".',
'headers.dl.history-bad-previous':
'This document contains a shortname change with previous shortname "${previousShortname}", but the it seems be not correct because "${url}" doesn\'t exist.',
'headers.dl.rescinds': 'Rescinds this Recommendation is missing.',
'headers.dl.rescinds-not-needed':
'Rescinds this Recommendation is included but does not seem necessary.',
'headers.dl.latest-rescinds-order':
'Latest Version must be before Rescinds this Recommendation.',
'headers.dl.this-rescinds-shortname':
'<em>Shortnames</em> differ between This Version (${thisShortname}) and Rescinds this Recommendation (${rescindsShortname}).',
'headers.dl.rescinds-syntax':
'Wrong syntax for Rescinds this Recommendation link.',
'headers.dl.obsoletes': 'Obsoletes this Recommendation is missing.',
'headers.dl.obsoletes-not-needed':
'Obsoletes this Recommendation is included but does not seem necessary.',
'headers.dl.latest-obsoletes-order':
'Latest Version must be before Obsoletes this Recommendation.',
'headers.dl.this-obsoletes-shortname':
'<em>Shortnames</em> differ between This Version and Obsoletes this Recommendation.',
'headers.dl.obsoletes-syntax':
'Wrong syntax for Obsoletes this Recommendation link.',
'headers.dl.supersedes': 'Supersedes this Recommendation is missing.',
'headers.dl.supersedes-not-needed':
'Supersedes this Recommendation is included but does not seem necessary.',
'headers.dl.latest-supersedes-order':
'Latest Version must be before Supersedes this Recommendation.',
'headers.dl.this-supersedes-shortname':
'<em>Shortnames</em> differ between This Version (${thisShortname}) and Supersedes this Recommendation (${obsoletesShortname}).',
'headers.dl.supersedes-syntax':
'Wrong syntax for Supersedes this Recommendation link.',
'headers.dl.implelink-should-be-https':
'Implementation report link should start with <em>https://</em>, current link in <code>&lt;dl&gt;</code> is: `${link}`.',
'headers.dl.implelink-confirm-no':
Expand Down
2 changes: 2 additions & 0 deletions lib/profiles/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import * as detailsSummary from '../rules/headers/details-summary.js';
import * as divHead from '../rules/headers/div-head.js';
import * as dl from '../rules/headers/dl.js';
import * as shortname from '../rules/headers/shortname.js';
import * as h1Title from '../rules/headers/h1-title.js';
import * as h2Toc from '../rules/headers/h2-toc.js';
import * as hr from '../rules/headers/hr.js';
Expand Down Expand Up @@ -37,6 +38,7 @@ export const rules = [
h1Title,
detailsSummary,
dl,
shortname,
w3cState,
h2Toc,
olToc,
Expand Down
172 changes: 10 additions & 162 deletions lib/rules/headers/dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
// #w3c-state date and this version date must match
// dt for editor or author

import superagent from 'superagent';
import doAsync from 'doasync';

const self = {
name: 'headers.dl',
section: 'front-matter',
Expand Down Expand Up @@ -55,12 +52,9 @@ function checkLink({ sr, rule = self, element, linkName, mustHave = true }) {

export async function check(sr, done) {
const { rescinds } = sr.config;
const { obsoletes } = sr.config;
const { supersedes } = sr.config;
const subType = sr.config.submissionType;
let topLevel = 'TR';
let thisURI = '';
let latestURI = '';

if (subType === 'member') topLevel = 'Submission';
else if (subType === 'team') topLevel = 'TeamSubmission';
Expand All @@ -71,24 +65,13 @@ export async function check(sr, done) {
if (!dts.History) sr.error(self, 'no-history');
if (rescinds && !dts.Rescinds) sr.error(self, 'rescinds');
if (!rescinds && dts.Rescinds) sr.warning(self, 'rescinds-not-needed');
if (obsoletes && !dts.Obsoletes) sr.error(self, 'obsoletes');
if (!obsoletes && dts.Obsoletes) sr.warning(self, 'obsoletes-not-needed');
if (supersedes && !dts.Supersedes) sr.error(self, 'supersedes');
if (!supersedes && dts.Supersedes)
sr.warning(self, 'supersedes-not-needed');

if (dts.This && dts.Latest && dts.This.pos > dts.Latest.pos)
sr.error(self, 'this-latest-order');
// TODO: What's the order for History?
if (dts.Latest && dts.Rescinds && dts.Latest.pos > dts.Rescinds.pos)
sr.error(self, 'latest-rescinds-order');
if (dts.Latest && dts.Obsoletes && dts.Latest.pos > dts.Obsoletes.pos)
sr.error(self, 'latest-obsoletes-order');
if (dts.Latest && dts.Supersedes && dts.Latest.pos > dts.Supersedes.pos)
sr.error(self, 'latest-supersedes-order');

let shortname;
let seriesShortname;
let matches;

if (dts.This) {
Expand All @@ -114,12 +97,6 @@ export async function check(sr, done) {
const year2 = matches[3] * 1;
const month = matches[4] * 1;
const day = matches[5] * 1;
[, , shortname] = matches;
const pattern = /-?\d[\d.]*$/;
const dashPattern = /\d[\d.]*-/;
seriesShortname = shortname
.replace(pattern, '')
.replace(dashPattern, '-');
if (docDate) {
if (
year !== docDate.getFullYear() ||
Expand All @@ -129,20 +106,10 @@ export async function check(sr, done) {
)
sr.error(self, 'this-date');
} else sr.warning(self, 'no-date');

// Require new /TR shortnames to use lowercase.
const shortnameChange =
dts.History &&
dts.History.dd.querySelector('a').dataset.previousShortname;
const needLowercase = shortnameChange || (await sr.isFP());
if (needLowercase && shortname.toLowerCase() !== shortname)
sr.error(thisError, 'shortname-lowercase', { shortname });
} else sr.error(thisError, 'this-syntax');
}
}

let sn;

if (dts.Latest) {
const linkLate = dts.Latest.dd.querySelector('a');
const exist = checkLink({
Expand All @@ -157,90 +124,21 @@ export async function check(sr, done) {
matches = (linkLate.getAttribute('href') || '')
.trim()
.match(new RegExp(lateRex));
if (matches) {
sn = matches[1];
// latest version link can be the shortlink or the series shortlink
if (sn === shortname) {
latestURI = linkLate.textContent;
} else if (sn === seriesShortname) {
latestURI = `https://www.w3.org/TR/${shortname}/`;
}
if (sn !== shortname && sn !== seriesShortname)
sr.error(self, 'this-latest-shortname', {
thisShortname: shortname,
latestShortname: sn,
});
} else sr.error(latestError, 'latest-syntax');

if (!matches) {
sr.error(latestError, 'latest-syntax');
}
}
}

if (dts.History) {
const linkHistory = dts.History.dd.querySelector('a');
const exist = checkLink({
checkLink({
sr,
rule: historyError,
element: linkHistory,
linkName: 'History',
});
if (exist) {
// e.g. https://www.w3.org/standards/history/hr-time-10086
const historyReg =
/^https:\/\/www\.w3\.org\/standards\/history\/(.+)$/;
matches = (linkHistory.getAttribute('href') || '')
.trim()
.match(historyReg);
if (matches) {
const [, historyShortname] = matches;
if (historyShortname !== shortname) {
sr.error(historyError, 'history-syntax', { shortname });
} else {
const historyHref = linkHistory.getAttribute('href');
// Check if the history link exist
let historyStatusCode;
try {
const res = await doAsync(superagent).head(historyHref);
historyStatusCode = res.statusCode;
} catch (err) {
historyStatusCode = err.status;
}
var hasPreviousVersion = !(await sr.isFP());
if (hasPreviousVersion && historyStatusCode === 404) {
// it's a none FP spec, but the history page doesn't exist. There should be a 'valid' previous-shortname.
const previousShortname = linkHistory.getAttribute(
'data-previous-shortname'
);
if (previousShortname) {
// prettier-ignore
sr.warning(historyError, 'this-previous-shortname',
{
previousShortname,
thisShortname: shortname,
}
);

// check previous shortname is valid.
const previousHistoryHref = `https://www.w3.org/standards/history/${previousShortname}`;
let previousHistoryStatusCode;
try {
const res = await doAsync(superagent).head(
previousHistoryHref
);
previousHistoryStatusCode = res.statusCode;
} catch (err) {
previousHistoryStatusCode = err.status;
}

if (previousHistoryStatusCode === 404) {
sr.error(historyError, 'history-bad-previous', {
previousShortname,
url: previousHistoryHref,
});
}
}
}
}
}
}
}

if (dts.Rescinds) {
Expand All @@ -251,68 +149,17 @@ export async function check(sr, done) {
element: linkRescinds,
linkName: 'Rescinds this Recommendation',
});
if (exist) {
matches = (linkRescinds.getAttribute('href') || '')
.trim()
.match(
/^https:\/\/www\.w3\.org\/TR\/\d{4}\/REC-(.+)-\d{8}\/?$/
);
if (matches) {
sn = matches[1];
if (sn !== shortname)
sr.error(self, 'this-rescinds-shortname', {
rescindsShortname: sn,
thisShortname: shortname,
});
} else sr.error(self, 'rescinds-syntax');
}
}

if (dts.Obsoletes) {
const linkObsl = dts.Obsoletes.dd.querySelector('a');
const exist = checkLink({
sr,
rule: self,
element: linkObsl,
linkName: 'Obsoletes this Recommendation',
});
if (exist) {
matches = (linkObsl.getAttribute('href') || '')
matches = (linkRescinds.getAttribute('href') || '')
.trim()
.match(
/^https:\/\/www\.w3\.org\/TR\/\d{4}\/REC-(.+)-\d{8}\/?$/
);
if (matches) {
sn = matches[1];
if (sn !== shortname)
sr.error(self, 'this-obsoletes-shortname', {
obsoletesShortname: sn,
thisShortname: shortname,
});
} else sr.error(self, 'obsoletes-syntax');
}
}

if (dts.Supersedes) {
const linkSpsd = dts.Supersedes.dd.querySelector('a');
const exist = checkLink({
sr,
rule: self,
element: linkSpsd,
linkName: 'Supersedes this Recommendation',
});

if (exist) {
matches = (linkSpsd.getAttribute('href') || '')
.trim()
.match(
/^https:\/\/www\.w3\.org\/TR\/\d{4}\/REC-(.+)-\d{8}\/?$/
);
if (matches) {
sn = matches[1];
if (sn !== shortname)
sr.error(self, 'this-supersedes-shortname');
} else sr.error(self, 'supersedes-syntax');
if (!matches) {
sr.error(self, 'rescinds-syntax');
}
}
}

Expand Down Expand Up @@ -382,5 +229,6 @@ export async function check(sr, done) {
// should at least have 1 editor
sr.error(editorError, 'editor-not-found');
}

done();
}
Loading

0 comments on commit 199e70f

Please sign in to comment.