Skip to content

Commit

Permalink
Add check for current charter. (#1326)
Browse files Browse the repository at this point in the history
* move charter extract function into validator.js

* Add check for current charter.

* fix test

* Update lib/validator.js

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

* remove () for single param for Arrow functions

* return error when joint-publication has different PP

* Make sure the pp version is consitant between the UI or the one defined in the charter.

* Update lib/rules/sotd/pp.js

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

* Update lib/l10n-en_GB.js

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

* Update lib/validator.js

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

* move charter extract function into validator.js

* Add check for current charter.

* fix test

* remove () for single param for Arrow functions

* Update lib/validator.js

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

* return error when joint-publication has different PP

* Make sure the pp version is consitant between the UI or the one defined in the charter.

* rename varibale, split metadata charters

* Add clear cache to newly added data

* 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]>

* Update lib/validator.js

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

* Update lib/validator.js

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

* Update lib/l10n-en_GB.js

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

* refine comment, remove eslint-ignore

Co-authored-by: Denis Ah-Kang <[email protected]>
  • Loading branch information
jennyliang220 and deniak authored Jul 26, 2021
1 parent e956f1e commit 0544bd7
Show file tree
Hide file tree
Showing 52 changed files with 534 additions and 291 deletions.
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"singleQuote": true
"singleQuote": true,
"arrowParens": "avoid"
}
20 changes: 10 additions & 10 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ l10n.setLanguage('en_GB');

server.listen(process.argv[2] || process.env.PORT || DEFAULT_PORT);

io.on('connection', (socket) => {
io.on('connection', socket => {
socket.emit('handshake', { version });
socket.on('extractMetadata', (data) => {
socket.on('extractMetadata', data => {
if (!data.url)
return socket.emit('exception', { message: 'URL not provided.' });
const vali = new validator.Specberus();
Expand Down Expand Up @@ -81,19 +81,19 @@ io.on('connection', (socket) => {
socket.emit('exception', err.message);
}
});
handler.on('end-all', (metadata) => {
handler.on('end-all', metadata => {
metadata.url = data.url;
socket.emit('finishedExtraction', metadata);
});
handler.on('exception', (data) => {
handler.on('exception', data => {
socket.emit('exception', data);
});
vali.extractMetadata({
url: data.url,
events: handler,
});
});
socket.on('validate', (data) => {
socket.on('validate', data => {
if (!data.url)
return socket.emit('exception', { message: 'URL not provided.' });
if (!data.profile)
Expand All @@ -109,7 +109,7 @@ io.on('connection', (socket) => {
const profile = util.profiles[data.profile];
const profileCode = profile.name;
socket.emit('start', {
rules: (profile.rules || []).map((rule) => rule.name),
rules: (profile.rules || []).map(rule => rule.name),
});
handler.on('err', (type, data) => {
try {
Expand Down Expand Up @@ -141,21 +141,21 @@ io.on('connection', (socket) => {
socket.emit('exception', err.message);
}
});
handler.on('done', (name) => {
handler.on('done', name => {
socket.emit('done', { name });
});
handler.on('end-all', () => {
socket.emit('finished');
});
handler.on('exception', (data) => {
handler.on('exception', data => {
socket.emit('exception', data);
});
insafe
.check({
url: data.url,
statusCodesAccepted: ['301', '406'],
})
.then((res) => {
.then(res => {
if (res.status) {
try {
vali.validate({
Expand All @@ -181,7 +181,7 @@ io.on('connection', (socket) => {
socket.emit('exception', { message });
}
})
.catch((e) => {
.catch(e => {
socket.emit('exception', {
message: `Insafe check blew up: ${e}`,
});
Expand Down
10 changes: 5 additions & 5 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const processRequest = function (req, res) {
(...data) => {
errors.push(Object.assign({}, ...data));
},
(data) => {
data => {
if (errors.length > 0)
sendJSONresult(errors, [], [], res, {});
else {
Expand Down Expand Up @@ -111,7 +111,7 @@ const processRequest = function (req, res) {
}
);
options2.events = handler2;
handler2.on('exception', (data) => {
handler2.on('exception', data => {
sendJSONresult(
[data.message ? data.message : data],
[],
Expand All @@ -124,7 +124,7 @@ const processRequest = function (req, res) {
}
}
);
handler.on('exception', (data) => {
handler.on('exception', data => {
sendJSONresult(
[data.message ? data.message : data],
[],
Expand All @@ -144,7 +144,7 @@ const processRequest = function (req, res) {
(...data) => {
errors.push(Object.assign({}, ...data));
},
(data) => {
data => {
sendJSONresult(errors, warnings, info, res, data.metadata);
},
(...data) => {
Expand All @@ -154,7 +154,7 @@ const processRequest = function (req, res) {
info.push(Object.assign({}, ...data));
}
);
handler.on('exception', (data) => {
handler.on('exception', data => {
sendJSONresult(
[data.message ? data.message : data],
[],
Expand Down
22 changes: 13 additions & 9 deletions lib/l10n-en_GB.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,21 @@ exports.messages = {
'sotd.pp.no-errata':
'No errata link was found in the patent policy section.',
'sotd.pp.no-response': 'The connection to the API failed: ${error}',
// sotd/charter-disclosure
'sotd.charter-disclosure.no-group': 'Unable to find the deliverer id.',
'sotd.charter-disclosure.text-not-found':
'sotd.pp.joint-different-pp':
'This document is published by multiple groups operating under different versions of the Patent Policy. A document should be published under one and only one Patent Policy, to which all participants in contributing groups have agreed.',
'sotd.pp.wrong-pp-from-charter':
'The Working Group delivering the document operates under the patent policy "${pp_charter}", but the check is against "${pp_config}". Please select the right patent policy to match the charter\'s version.',
// sotd/charter
'sotd.charter.no-group':
'Unable to find the group(s) ID(s) (in the <code>data-deliverer</code> attribute for Note-Track documents, and in the "Status of This Document" for REC-Track documents).',
'sotd.charter.text-not-found':
'No texts about charter for disclosure obligations found.',
'sotd.charter-disclosure.link-not-found':
'sotd.charter.link-not-found':
'No link to charter for disclosure obligations found.',
'sotd.charter-disclosure.wrong-link':
'sotd.charter.wrong-link':
"The link to charter for disclosure obligations should be <a href='${expectedHref}'>${expectedHref}</a>.",
'sotd.charter-disclosure.no-charter':
'The group does not have any living charter, please contact the team contact.',
'sotd.charter-disclosure.no-response':
'The connection to the API failed: HTTP ${status}',
'sotd.charter.no-charter':
'The group does not have any current charter, please contact the team contact.',
// sotd/rec-addition
'sotd.rec-addition.no-correction':
'This document contains substantive changes, cannot find corresponding paragraph <code>&lt;p class="correction"&gt;Proposed corrections are marked in the document.&lt;/p&gt;</code>',
Expand Down Expand Up @@ -387,4 +390,5 @@ exports.messages = {
'metadata.title': false,
'metadata.errata': false,
'metadata.patent-policy': false,
'metadata.charters': false,
};
1 change: 1 addition & 0 deletions lib/profiles/TR.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports.rules = base.extendWithInserts({
require('../rules/sotd/draft-stability'),
require('../rules/sotd/status'),
require('../rules/sotd/pp'),
require('../rules/sotd/charter'),
require('../rules/sotd/process-document'),
],
});
1 change: 0 additions & 1 deletion lib/profiles/TR/IG-NOTE.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ exports.config = {

const base = require('../base');
let rules = base.insertAfter(require('../TR').rules, 'sotd.pp', [
require('../../rules/sotd/charter-disclosure'),
require('../../rules/sotd/diff'),
require('../../rules/sotd/deliverer-note'),
]);
Expand Down
8 changes: 4 additions & 4 deletions lib/profiles/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ exports.name = 'Base';
exports.insertAfter = function (original, anchor, rules) {
rules = Array.isArray(rules) ? rules : [rules];
original = original.slice();
let index = original.map((r) => r.name).indexOf(anchor);
let index = original.map(r => r.name).indexOf(anchor);
if (index < 0) return original.concat(rules);

rules.forEach((r) => {
rules.forEach(r => {
original.splice(index, 0, r);
index++;
});
Expand All @@ -27,8 +27,8 @@ exports.extendWithInserts = function (inserts) {
exports.removeRules = function (original, rules) {
rules = Array.isArray(rules) ? rules : [rules];
original = original.slice();
rules.forEach((r) => {
const index = original.map((rule) => rule.name).indexOf(r);
rules.forEach(r => {
const index = original.map(rule => rule.name).indexOf(r);
if (index >= 0) {
original.splice(index, 1);
}
Expand Down
1 change: 1 addition & 0 deletions lib/profiles/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exports.rules = [
require('../rules/metadata/dl'),
require('../rules/metadata/deliverers'),
require('../rules/metadata/patent-policy'),
require('../rules/metadata/charters'),
require('../rules/metadata/editor-ids'),
require('../rules/metadata/editor-names'),
require('../rules/metadata/rectrack'),
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/headers/dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,12 @@ exports.check = function (sr, done) {
const editors = dts.Editor.dd;
// 'missingElement' is array of HTML elements without editorId
const missingElement = editors.filter(
(editor) => !editor.dataset.editorId
editor => !editor.dataset.editorId
);
if (missingElement.length) {
sr.error(editorError, 'editor-missing-id', {
names: missingElement
.map((editor) => editor.textContent)
.map(editor => editor.textContent)
.join(', '),
});
}
Expand All @@ -366,7 +366,7 @@ exports.check = function (sr, done) {
done();
} else {
PowerPromise.all([fetch(previousURI), fetch(latestURI)]).then(
(bodies) => {
bodies => {
if (!bodies || bodies.length !== 2) {
sr.error(self, 'cant-retrieve');
} else if (bodies[0] !== bodies[1]) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/headers/errata.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports.check = function (sr, done) {
const errataRegex = /errata/i;
const errata = Array.prototype.filter.call(
sr.jsDocument.querySelectorAll('body div.head dl + p > a'),
(element) => errataRegex.test(element.textContent)
element => errataRegex.test(element.textContent)
);
if (!errata.length || !errata[0].getAttribute('href'))
sr.error(self, 'not-found');
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/headers/github-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports.check = function (sr, done) {
const dl = sr.jsDocument.querySelector('body div.head dl');
if (dl) {
let foundRepo = false;
dl.querySelectorAll('a[href]').forEach((a) => {
dl.querySelectorAll('a[href]').forEach(a => {
const href = a.getAttribute('href');
// eg: https://github.com/xxx/xxx/issues/
if (
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/headers/memsub-copyright.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports.check = function (sr, done) {
// , "http://www.w3.org/Consortium/Legal/copyright-documents": "document use"
const seen = Array.prototype.some.call(
copyright.querySelectorAll('a[href]'),
(a) =>
a =>
a
.getAttribute('href')
.indexOf(
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/links/compound.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports.check = function (sr, done) {
let links = [];

if (sr.url) {
sr.jsDocument.querySelectorAll('a[href]').forEach((element) => {
sr.jsDocument.querySelectorAll('a[href]').forEach(element => {
const u = new url.URL(element.getAttribute('href'), sr.url);
const l = u.origin + u.pathname;
if (l.startsWith(sr.url) && l !== sr.url) links.push(l);
Expand All @@ -29,15 +29,15 @@ exports.check = function (sr, done) {
const markupService = 'https://validator.w3.org/nu/';
let count = 0;
if (links.length > 0) {
links.forEach((l) => {
links.forEach(l => {
if (sr.config.validation === 'recursive') {
const ua = `W3C-Pubrules/${sr.version}`;
let isMarkupValid = false;
const req = sua
.get(markupService)
.set('User-Agent', ua)
.query({ doc: l, out: 'json' })
.on('error', (err) => {
.on('error', err => {
sr.error(self, 'error', {
file: l.split('/').pop(),
link: l,
Expand All @@ -53,7 +53,7 @@ exports.check = function (sr, done) {
if (!json) return sr.throw('No JSON input.');
if (json.messages) {
const errors = json.messages.filter(
(msg) => msg.type === 'error'
msg => msg.type === 'error'
);
if (errors.length === 0) isMarkupValid = true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/links/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const self = {
exports.name = self.name;

exports.check = function (sr, done) {
sr.jsDocument.querySelectorAll("a[href^='#']").forEach((element) => {
sr.jsDocument.querySelectorAll("a[href^='#']").forEach(element => {
const id = element.getAttribute('href').replace('#', '');
const escId = id.replace(/([.()#:[\]+*])/g, '\\$1');
if (id === '') return;
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/links/linkchecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function simplifyURL(url) {

// Upgrade version of Array.include(). The array can be RegExp
function includedByReg(url, regArray = allowList) {
return regArray.some((item) => {
return regArray.some(item => {
if (typeof item === 'object') {
// item is RegExp
return item.test(url);
Expand All @@ -64,7 +64,7 @@ exports.check = async function (sr, done) {
const browser = await puppeteer.launch();
const page = await browser.newPage();

page.on('response', (response) => {
page.on('response', response => {
const url = simplifyURL(response.url());
const { referer } = response.request()._headers;
const docPath = sr.url.replace(/\/[^/]+$/, '/');
Expand Down
58 changes: 28 additions & 30 deletions lib/rules/links/reliability.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,34 @@ const unreliableServices = [
];

exports.check = function (sr, done) {
Array.prototype.some.call(
sr.jsDocument.querySelectorAll('a'),
(element) => {
let url;
try {
url = new URL(element.href, sr.url || 'https://www.w3.org');
} catch (e) {
// when failed to parse URL, move on to next one.
return false;
}

const domain = url && url.hostname;
const path = url && url.pathname;
// eslint-disable-next-line
unreliableServices.some((unreliableService) => {
if (
domain === unreliableService.domain &&
(!unreliableService.path ||
(unreliableService.path &&
unreliableService.path.test(path)))
) {
sr.warning(self, 'unreliable-link', {
link: element.href,
text: sr.norm(element.textContent),
});
// when finding this URL unreliable, quit 'unreliableServices.some'
return true;
}
});
Array.prototype.some.call(sr.jsDocument.querySelectorAll('a'), element => {
let url;
try {
url = new URL(element.href, sr.url || 'https://www.w3.org');
} catch (e) {
// when failed to parse URL, move on to next one.
return false;
}
);

const domain = url && url.hostname;
const path = url && url.pathname;

unreliableServices.some(unreliableService => {
if (
domain === unreliableService.domain &&
(!unreliableService.path ||
(unreliableService.path &&
unreliableService.path.test(path)))
) {
sr.warning(self, 'unreliable-link', {
link: element.href,
text: sr.norm(element.textContent),
});
// when finding this URL unreliable, quit 'unreliableServices.some'
return true;
}
return false;
});
});
done();
};
Loading

0 comments on commit 0544bd7

Please sign in to comment.