Skip to content

Commit

Permalink
fix: update axioms, fixes and rules for documentation
Browse files Browse the repository at this point in the history
documentation upgrade from 13.2.5 to 14.0.0 is a breaking change.
Update the *require* solution does the trick.
  • Loading branch information
Neil Zhao committed Oct 20, 2022
1 parent 75ad099 commit 7432dfe
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 52 deletions.
7 changes: 6 additions & 1 deletion axioms/axioms.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// Copyright 2017 TODO Group. All rights reserved.
// Licensed under the Apache License, Version 2.0.

module.exports = ['licensee', 'linguist', 'packagers', 'contributor-count']
module.exports = {
licensee: require('./licensee'),
linguist: require('./linguist'),
packagers: require('./packagers'),
'contributor-count': require('./contributor-count')
}
6 changes: 5 additions & 1 deletion fixes/fixes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Copyright 2017 TODO Group. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

module.exports = ['file-create', 'file-modify', 'file-remove']
module.exports = {
'file-create': require('./file-create'),
'file-modify': require('./file-modify'),
'file-remove': require('./file-remove')
}
33 changes: 6 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,7 @@ async function lint(
* An object containing JS file names associated with their appropriate require function
*/
async function loadRules() {
// convert the lists into a easily-loadable object
return Rules.map(f => [
f,
() => require(path.resolve(__dirname, './rules/', f))
]).reduce((p, [name, require]) => {
p[name] = require
return p
}, {})
return Rules
}

/**
Expand All @@ -248,14 +241,7 @@ async function loadRules() {
* An object containing JS file names associated with their appropriate require function
*/
async function loadFixes() {
// convert the lists into a easily-loadable object
return Fixes.map(f => [
f,
() => require(path.resolve(__dirname, './fixes/', f))
]).reduce((p, [name, require]) => {
p[name] = require
return p
}, {})
return Fixes
}

/**
Expand All @@ -273,14 +259,7 @@ async function loadFixes() {
* An object containing JS file names associated with their appropriate require function
*/
async function loadAxioms() {
// convert the lists into a easily-loadable object
return Axioms.map(f => [
f,
() => require(path.resolve(__dirname, './axioms/', f))
]).reduce((p, [name, require]) => {
p[name] = require
return p
}, {})
return Axioms
}

/**
Expand Down Expand Up @@ -405,7 +384,7 @@ async function runRuleset(ruleset, targets, fileSystem, dryRun) {
let result
try {
// load the rule
const ruleFunc = allRules[r.ruleType]()
const ruleFunc = allRules[r.ruleType]
// run the rule!
result = await ruleFunc(fileSystem, r.ruleConfig)
} catch (e) {
Expand All @@ -429,7 +408,7 @@ async function runRuleset(ruleset, targets, fileSystem, dryRun) {
}
let fixresult
try {
const fixFunc = allFixes[r.fixType]()
const fixFunc = allFixes[r.fixType]
fixresult = await fixFunc(fileSystem, r.fixConfig, fixTargets, dryRun)
} catch (e) {
return FormatResult.CreateError(
Expand Down Expand Up @@ -465,7 +444,7 @@ async function determineTargets(axiomconfig, fs) {
new Result(`invalid axiom name ${axiomId}`, [], false)
]
}
const axiomFunction = allAxioms[axiomId]()
const axiomFunction = allAxioms[axiomId]
return [axiomName, await axiomFunction(fs)]
})
)
Expand Down
4 changes: 2 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ async function validateConfig(config) {
const ajvProps = new Ajv()
// find all json schemas
const parsedRuleSchemas = Promise.all(
Rules.map(rs =>
Object.keys(Rules).map(rs =>
jsonfile.readFile(
path.resolve(__dirname, '../rules', `${rs}-config.json`)
)
)
)
const parsedFixSchemas = Promise.all(
Fixes.map(f =>
Object.keys(Fixes).map(f =>
jsonfile.readFile(path.resolve(__dirname, '../fixes', `${f}-config.json`))
)
)
Expand Down
42 changes: 21 additions & 21 deletions rules/rules.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// Copyright 2017 TODO Group. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

module.exports = [
'apache-notice',
'best-practices-badge-present',
'directory-existence',
'file-contents',
'file-existence',
'file-hash',
'file-hashes-not-exist',
'file-no-broken-links',
'file-not-contents',
'file-not-exists',
'file-starts-with',
'file-type-exclusion',
'git-grep-commits',
'git-grep-log',
'git-list-tree',
'git-working-tree',
'large-file',
'license-detectable-by-licensee',
'json-schema-passes'
]
module.exports = {
'apache-notice': require('./apache-notice'),
'best-practices-badge-present': require('./best-practices-badge-present'),
'directory-existence': require('./directory-existence'),
'file-contents': require('./file-contents'),
'file-existence': require('./file-existence'),
'file-hash': require('./file-hash'),
'file-hashes-not-exist': require('./file-hashes-not-exist'),
'file-no-broken-links': require('./file-no-broken-links'),
'file-not-contents': require('./file-not-contents'),
'file-not-exists': require('./file-not-exists'),
'file-starts-with': require('./file-starts-with'),
'file-type-exclusion': require('./file-type-exclusion'),
'git-grep-commits': require('./git-grep-commits'),
'git-grep-log': require('./git-grep-log'),
'git-list-tree': require('./git-list-tree'),
'git-working-tree': require('./git-working-tree'),
'large-file': require('./large-file'),
'license-detectable-by-licensee': require('./license-detectable-by-licensee'),
'json-schema-passes': require('./json-schema-passes')
}

0 comments on commit 7432dfe

Please sign in to comment.