-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for reporting references to discontinued specs
- Loading branch information
1 parent
994260f
commit 48ddd6e
Showing
3 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { recordCategorizedAnomaly } = require('./util'); | ||
|
||
const possibleAnomalies = [ | ||
'discontinuedReferences' | ||
]; | ||
|
||
function studyReferences (edResults) { | ||
const report = []; | ||
const recordAnomaly = recordCategorizedAnomaly(report, 'refs', possibleAnomalies); | ||
edResults.forEach(spec => { | ||
(spec.refs?.normative || []).forEach(ref => { | ||
const referencedSpec = edResults.find(s => s.url === ref.url || s?.nightly.url === ref.url || s?.nightly?.alternateUrls?.includes(ref.url)); | ||
|
||
if (referencedSpec && referencedSpec.standing === "discontinued") { | ||
|
||
const newSpecsLinks = edResults.filter(s => referencedSpec.obsoletedBy?.includes(s.shortname)).map(s => `[${s.shortname}](${s?.nightly.url || s.url})`); | ||
recordAnomaly(spec, 'discontinuedReferences', `[${ref.name}](${ref.url}) ${newSpecsLinks.length ? `has been obsoleted by ${newSpecsLinks}` : `is discontinued, no known replacement reference`}`); | ||
} | ||
}); | ||
}); | ||
return report; | ||
} | ||
|
||
module.exports = { studyReferences }; | ||
|
||
if (require.main === module) { | ||
(async function() { | ||
const { loadCrawlResults } = require('../lib/util'); | ||
const crawl = await loadCrawlResults(process.argv[2]); | ||
const results = studyReferences(crawl.ed); | ||
console.log(results); | ||
})(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Tests the links analysis library. | ||
*/ | ||
/* global describe, it */ | ||
|
||
const { studyReferences } = require('../src/lib/study-refs'); | ||
const { assertNbAnomalies, assertAnomaly } = require('./util'); | ||
|
||
const specEdUrl = 'https://w3c.github.io/spec/'; | ||
const specEdUrl2 = 'https://w3c.github.io/spec2/'; | ||
const specEdUrl3 = 'https://w3c.github.io/spec3/'; | ||
|
||
function toRefs (name, url) { | ||
return [ {name, url} ]; | ||
} | ||
|
||
|
||
const populateSpec = (url, refs = [], standing = "good", obsoletedBy) => { | ||
const shortname = url.slice(0, -1).split('/').pop(); | ||
return { | ||
url: url, | ||
refs: { | ||
normative: refs | ||
}, | ||
nightly: { | ||
url | ||
}, | ||
shortname, | ||
standing, | ||
obsoletedBy | ||
}; | ||
}; | ||
|
||
function toEdCrawlResults (standing = "good", replacements) { | ||
return [ | ||
populateSpec(specEdUrl, toRefs("spec2", specEdUrl2)), | ||
populateSpec(specEdUrl2, [], standing, replacements), | ||
populateSpec(specEdUrl3) | ||
]; | ||
} | ||
|
||
describe('The reference analyser', () => { | ||
it('reports no anomaly if references are not discontinued', () => { | ||
const crawlResult = toEdCrawlResults(); | ||
const report = studyReferences(crawlResult); | ||
assertNbAnomalies(report, 0); | ||
}); | ||
|
||
it('reports a discontinued reference with a replacement', () => { | ||
const crawlResult = toEdCrawlResults("discontinued", ["spec3"]); | ||
const report = studyReferences(crawlResult); | ||
assertNbAnomalies(report, 1); | ||
assertAnomaly(report, 0, { | ||
category: 'refs', | ||
message: /spec3/ | ||
}); | ||
}); | ||
|
||
it('reports a discontinued reference without a replacement', () => { | ||
const crawlResult = toEdCrawlResults("discontinued"); | ||
const report = studyReferences(crawlResult); | ||
assertNbAnomalies(report, 1); | ||
assertAnomaly(report, 0, { | ||
category: 'refs', | ||
message: /no known replacement/ | ||
}); | ||
}); | ||
|
||
}); |