Skip to content

Commit

Permalink
feat: add relative path resolving to rulesetPath
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Zhao <neil.leopard@gmail.com>
  • Loading branch information
zhaoyuheng200 authored and hyandell committed Oct 27, 2023
1 parent fff69cc commit 561e895
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/** @module repolinter */

const path = require('path')
const fs = require('fs')
const config = require('./lib/config')
const Result = require('./lib/result')
const RuleInfo = require('./lib/ruleinfo')
Expand Down Expand Up @@ -132,7 +133,12 @@ async function lint(
if (config.isAbsoluteURL(ruleset)) {
rulesetPath = ruleset
} else {
rulesetPath = path.resolve(targetDir, ruleset)
if (fs.existsSync(path.resolve(targetDir, ruleset))) {
rulesetPath = path.resolve(targetDir, ruleset)
}
if (fs.existsSync(path.resolve(__dirname, ruleset))) {
rulesetPath = path.resolve(__dirname, ruleset)
}
}
} else if (!ruleset) {
rulesetPath = config.findConfig(targetDir)
Expand Down
5 changes: 4 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ async function validateConfig(config) {
return {
passed: false,
error: `Configuration validation failed with errors: \n${validator.errors
.map(e => `\tconfiguration${e.dataPath} ${e.message}`)
.map(
e =>
`\tconfiguration${e.dataPath} ${e.message}\n\nIt's likely the rulesetPath or rulesetUrl isn't configured correctly.`
)
.join('\n')}`
}
} else {
Expand Down
10 changes: 2 additions & 8 deletions tests/cli/cli_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,8 @@ describe('cli', function () {

expect(actual.code).to.equal(1)
expect(actual2.code).to.equal(1)
expect(actual.out.trim()).to.contain.oneOf([
'Error: ENAMETOOLONG: name too long',
'Error: ENOENT: no such file or directory, open '
])
expect(actual2.out.trim()).to.contain.oneOf([
'Error: ENAMETOOLONG: name too long',
'Error: ENOENT: no such file or directory, open '
])
expect(actual.out.trim()).to.contain('configuration should be object')
expect(actual2.out.trim()).to.contain('configuration should be object')
})
it('should handle encoded rulesets with encoded extends', async () => {
const encodedRuleset =
Expand Down

0 comments on commit 561e895

Please sign in to comment.