Skip to content

Commit

Permalink
Configure ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
foolip committed May 16, 2019
1 parent c26974a commit 30903f4
Show file tree
Hide file tree
Showing 12 changed files with 1,367 additions and 465 deletions.
15 changes: 15 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"env": {
"es6": true,
"browser": true,
"node": true
},
"extends": ["eslint:recommended", "google"],
"rules": {
"no-console": "off",
"require-jsdoc": "off"
},
"parserOptions": {
"ecmaVersion": 2017
}
}
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ branches:
language: node_js
node_js: stable
script:
- npm run lint
- ./build.sh
- ./check.sh
deploy:
Expand Down
103 changes: 56 additions & 47 deletions build/check-missing-specs.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'
'use strict';

const GitHub = require('github-api')
const URL = require('url').URL
const fetch = require('node-fetch')
const fs = require('fs')
const JSDOM = require('jsdom').JSDOM
const GitHub = require('github-api');
const URL = require('url').URL;
const fetch = require('node-fetch');
const fs = require('fs');
const JSDOM = require('jsdom').JSDOM;

const orgs = ['w3c', 'wicg']
const orgs = ['w3c', 'wicg'];

// repos that aren't specs or are abandoned, and that would either cause errors
// or contribute boring URLs.
Expand Down Expand Up @@ -289,85 +289,94 @@ const REPO_BLOCKLIST = new Set([
'w3c/wptdashboard',
'w3c/wptrunner',
'w3c/wpub',
])
]);

function normalizeUrl(urlString) {
const url = new URL(urlString)
url.protocol = 'https:'
return url.toString()
const url = new URL(urlString);
url.protocol = 'https:';
return url.toString();
}

// fetches url and follows <meta http-equiv=refresh> redirects. Returns the
// final response and has no protection against redirect loops.
async function followRedirects(url) {
const response = await fetch(url)
if (response.status != 200)
return response
const response = await fetch(url);
if (response.status != 200) {
return response;
}

// parse the response as HTML to find <meta http-equiv=refresh>
const text = await response.text()
const document = new JSDOM(text).window.document
const metas = document.querySelectorAll('meta[http-equiv=refresh i][content]')
const text = await response.text();
const document = new JSDOM(text).window.document;
const metas = document.querySelectorAll(
'meta[http-equiv=refresh i][content]');

for (let i = 0; i < metas.length; i++) {
const content = metas[i].getAttribute('content')
const content = metas[i].getAttribute('content');

// do something simple, the correct behavior is complicated:
// https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-refresh
try {
const url = normalizeUrl(content.split('=')[1].replace(/['" ]/g, ''))
return followRedirects(url)
} catch(e) {}
const url = normalizeUrl(content.split('=')[1].replace(/['" ]/g, ''));
return followRedirects(url);
} catch (e) {
// swallow error
}
}

return response
return response;
}

async function main() {
const specsPath = process.argv[2]
console.assert(specsPath)
const specs = JSON.parse(fs.readFileSync(specsPath))
const specsPath = process.argv[2];
console.assert(specsPath);
const specs = JSON.parse(fs.readFileSync(specsPath));

const token = process.env.GH_TOKEN
if (!token)
console.warn('Warning: no GitHub token given, provide it via GH_TOKEN')
const token = process.env.GH_TOKEN;
if (!token) {
console.warn('Warning: no GitHub token given, provide it via GH_TOKEN');
}

const gh = new GitHub({ token: token })
const gh = new GitHub({token: token});

const fetches = []
const fetches = [];

for (const org of orgs) {
const repos = (await gh.getOrganization(org).getRepos()).data
const repos = (await gh.getOrganization(org).getRepos()).data;

console.log(`Checking ${repos.length} ${org} repos`)
console.log(`Checking ${repos.length} ${org} repos`);
for (const repo of repos) {
const url = `https://${org}.github.io/${repo.name}/`
const url = `https://${org}.github.io/${repo.name}/`;

if (REPO_BLOCKLIST.has(repo.full_name))
continue
if (REPO_BLOCKLIST.has(repo.full_name)) {
continue;
}

if (specs.some(spec => spec.href.startsWith(url)))
continue
if (specs.some((spec) => spec.href.startsWith(url))) {
continue;
}

fetches.push(followRedirects(url))
fetches.push(followRedirects(url));
}
}

const responses = (await Promise.all(fetches)).filter(r => r.status == 200)
const responses = (await Promise.all(fetches)).filter((r) => r.status == 200);

// make responses unique (we can end up at the same URL many times)
const urlMap = new Map
const urlMap = new Map;
for (const response of responses) {
if (!urlMap.has(response.url))
urlMap.set(response.url, response)
if (!urlMap.has(response.url)) {
urlMap.set(response.url, response);
}
}

console.log(`URLs not in ${specsPath}:`)
console.log(`URLs not in ${specsPath}:`);
for (const response of urlMap.values()) {
const url = response.url
if (!specs.some(spec => spec.href.startsWith(url)))
console.log(` ${url}`)
const url = response.url;
if (!specs.some((spec) => spec.href.startsWith(url))) {
console.log(` ${url}`);
}
}
}

main()
main();
22 changes: 11 additions & 11 deletions build/check-test-policy.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict'
'use strict';

const fs = require('fs')
const fs = require('fs');

const dataPath = process.argv[3]
console.assert(dataPath)
const dataPath = process.argv[3];
console.assert(dataPath);

console.log(`Reading ${dataPath}`)
const specs = JSON.parse(fs.readFileSync(dataPath)).specs
console.log(`Reading ${dataPath}`);
const specs = JSON.parse(fs.readFileSync(dataPath)).specs;

const specsWithoutTestPolicy = specs.filter(spec => !spec.testpolicy)
const specsWithoutTestPolicy = specs.filter((spec) => !spec.testpolicy);
if (specsWithoutTestPolicy.length) {
console.log('Specs with no (known) testing policy:')
specsWithoutTestPolicy.forEach(entry => {
console.log(` ${entry.name} <${entry.href}>`)
})
console.log('Specs with no (known) testing policy:');
specsWithoutTestPolicy.forEach((entry) => {
console.log(` ${entry.name} <${entry.href}>`);
});
}
68 changes: 37 additions & 31 deletions build/check-wpt-dirs.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'
'use strict';

const execSync = require('child_process').execSync
const fs = require('fs')
const repo = require('./repo')
const execSync = require('child_process').execSync;
const fs = require('fs');
const repo = require('./repo');

const IGNORE_WPT_DIRS = new Set([
'acid', // Acid2 and Acid3
Expand Down Expand Up @@ -37,60 +37,66 @@ const IGNORE_WPT_DIRS = new Set([
'tools',
'wai-aria', // http://w3c.github.io/aria/aria/aria.html
'wasm', // https://github.com/WebAssembly/spec/issues/529
])
]);

function findWptDirs(dir) {
const cmd = 'find * -maxdepth 0 -type d -print0; find css/* -maxdepth 0 -type d -print0'
const dirs = execSync(cmd, { cwd: dir }).toString().split('\0').filter(dir => dir != '')
dirs.sort()
return new Set(dirs)
const cmd = 'find * -maxdepth 0 -type d -print0; ' +
'find css/* -maxdepth 0 -type d -print0';
const dirs = execSync(cmd, {cwd: dir})
.toString().split('\0').filter((dir) => dir != '');
dirs.sort();
return new Set(dirs);
}

function main() {
const specsPath = process.argv[2]
console.assert(specsPath)
const specsPath = process.argv[2];
console.assert(specsPath);

console.log(`Reading ${specsPath}`)
const specs = JSON.parse(fs.readFileSync(specsPath))
console.log(`Reading ${specsPath}`);
const specs = JSON.parse(fs.readFileSync(specsPath));

// set of all dirs that (currently) really exist in wpt
const wptDir = repo.checkout('https://github.com/w3c/web-platform-tests', { update: false })
const realWptDirs = findWptDirs(wptDir)
const wptDir = repo.checkout('https://github.com/w3c/web-platform-tests', {update: false});
const realWptDirs = findWptDirs(wptDir);

// set of all dirs in wpt that are used by some entry
const usedWptDirs = new Set
const usedWptDirs = new Set;

// list of specs (entries) for which no tests are found in wpt
const specsWithoutWptDirs = []
const specsWithoutWptDirs = [];

for (const entry of specs) {
// skips specs where the tests aren't int wpt
if (entry.testrepo && !entry.testrepo != 'w3c/web-platform-tests')
continue
if (entry.testrepo && !entry.testrepo != 'w3c/web-platform-tests') {
continue;
}

// Note: some of the dirs may not exist, they are the arguments to git log
// TODO: this duplicates logic (entry.testpath || entry.id) in data.js
const dirs = (entry.testpath || entry.id).split(' ')
const dirs = (entry.testpath || entry.id).split(' ');

dirs.forEach(dir => usedWptDirs.add(dir))
dirs.forEach((dir) => usedWptDirs.add(dir));

if (!dirs.some(dir => realWptDirs.has(dir)))
specsWithoutWptDirs.push(entry)
if (!dirs.some((dir) => realWptDirs.has(dir))) {
specsWithoutWptDirs.push(entry);
}
}

if (specsWithoutWptDirs.length) {
console.log('Specs without tests (in wpt):')
for (const entry of specsWithoutWptDirs)
console.log(` ${entry.name} <${entry.href}>`)
console.log('Specs without tests (in wpt):');
for (const entry of specsWithoutWptDirs) {
console.log(` ${entry.name} <${entry.href}>`);
}
}

const wptDirsWithoutSpec = Array.from(realWptDirs)
.filter(dir => !usedWptDirs.has(dir) && !IGNORE_WPT_DIRS.has(dir))
.filter((dir) => !usedWptDirs.has(dir) && !IGNORE_WPT_DIRS.has(dir));
if (wptDirsWithoutSpec.length) {
console.log('Directories (in wpt) without spec:')
for (const dir of wptDirsWithoutSpec)
console.log(` ${dir}`)
console.log('Directories (in wpt) without spec:');
for (const dir of wptDirsWithoutSpec) {
console.log(` ${dir}`);
}
}
}

main()
main();
Loading

0 comments on commit 30903f4

Please sign in to comment.