Skip to content

Commit

Permalink
fix: add backwards compatibility for blacklist -> denylist switch
Browse files Browse the repository at this point in the history
  • Loading branch information
prototypicalpro committed Aug 28, 2020
1 parent 53e570a commit 002deae
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* `async` was added to the function interface.
* Major changes have been make to the [JSON Formatter](index.js) to accommodate the structure change of `LintResult`.
* Non top-level configuration support (ex. `targetdir/otherdir/repolinter.json` would trigger another lint of `otherdir`) has been removed for now.
* Renamed several rule options to more clearly convey functionality (`files` -> `globsAny`) and remove problematic language (`blacklist` -> `denylist`). Backwards compatibility for old property names in version 1 rulesets is still maintained, however the schema will fail to validate in version 2.
* Some slight changes have been made to the default formatter to accommodate the feature list below.

### Features
Expand Down
3 changes: 3 additions & 0 deletions rules/git-grep-commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ function listFiles (fileSystem, options) {
* @returns {Result} The lint rule result
*/
function gitGrepCommits (fs, options) {
// backwards compatibility with blacklist
options.denylist = options.denylist || options.blacklist

const files = listFiles(fs, options)
const targets = files.map(file => {
const [firstCommit, ...rest] = file.commits
Expand Down
3 changes: 3 additions & 0 deletions rules/git-grep-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ function extractInfo (commit) {
* @returns {Result} The lint rule result
*/
function gitGrepLog (fs, options) {
// backwards compatibility with blacklist
options.denylist = options.denylist || options.blacklist

const commits = grepLog(fs, options)

const targets = commits.map(commit => {
Expand Down
3 changes: 3 additions & 0 deletions rules/git-list-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ function listFiles (fileSystem, options) {
* @returns {Result} The lint rule result
*/
function gitListTree (fs, options) {
// backwards compatibility with blacklist
options.denylist = options.denylist || options.blacklist

const files = listFiles(fs, options)

const targets = files.map(file => {
Expand Down
12 changes: 12 additions & 0 deletions tests/rules/git_grep_commits_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ describe('rule', () => {
expect(actual.message).to.contain(ruleopts.denylist[0])
})

it('is backwards compatible with blacklist', () => {
const ruleopts = {
blacklist: [DIFF_WRONG_CASE],
ignoreCase: false
}

const actual = gitGrepCommits(new FileSystem(), ruleopts)

expect(actual.passed).to.equal(true)
expect(actual.message).to.contain(ruleopts.blacklist[0])
})

it('fails if the denylist pattern matches a commit', () => {
const ruleopts = {
denylist: [DIFF_CORRECT_CASE],
Expand Down
13 changes: 13 additions & 0 deletions tests/rules/git_grep_log_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ describe('rule', () => {
expect(actual.message).to.contain(ruleopts.denylist[0])
})

it('is backwards compatible with blacklist', () => {
const ruleopts = {
blacklist: [LOG_WRONG_CASE],
ignoreCase: false
}

const actual = gitGrepLog(new FileSystem(), ruleopts)

expect(actual.passed).to.equal(true)
expect(actual.targets).to.have.length(0)
expect(actual.message).to.contain(ruleopts.blacklist[0])
})

it('fails if the denylist pattern matches a commit message', () => {
const ruleopts = {
denylist: [LOG_WRONG_CASE],
Expand Down
12 changes: 12 additions & 0 deletions tests/rules/git_list_tree_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ describe('rule', () => {
expect(actual.targets).to.have.length(0)
})

it('is backwards compatible with blacklist', () => {
const ruleopts = {
blacklist: [PATH_WRONG_CASE],
ignoreCase: false
}

const actual = gitListTree(new FileSystem(), ruleopts)

expect(actual.passed).to.equal(true)
expect(actual.targets).to.have.length(0)
})

it('fails if the denylist pattern matches a path', () => {
const ruleopts = {
denylist: [PATH_WRONG_CASE],
Expand Down

0 comments on commit 002deae

Please sign in to comment.