Skip to content

Commit 632ff25

Browse files
authored
Added excludeExact option for concise file exclusion (#87)
1 parent 0489d4e commit 632ff25

File tree

6 files changed

+33
-9
lines changed

6 files changed

+33
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ To customise your analysis, use the following options, placed in a `codehawk.jso
119119
| `extensions` | File extensions that should be analyzed. The default is always used, but you can add more extensions. You can use the `exclude[...]` options to exclude specific files. | `['.js', '.jsx', '.ts', '.tsx']` |
120120
| `excludeFilenames` | Filename matches that should be excluded from static analysis (but still show in the data). The default is always used, but you can add more matches to be excluded. Note that the matching is exact. The exclude list is taken into consideration after the extension list. | `['.d.ts', '.min.js', '.bundle.js']` |
121121
| `excludeDirectories` | Directory matches that should be excluded from static analysis (but still show in the data). Relative to the root. E.g. `['/fixtures', '/test']` | `['/dist', '/bin', '/build']` |
122+
| `excludeExact` | Exact file matches that should be excluded from static analysis (but still show in the data). Relative to the root. E.g. `['/src/foo/bar.ts']` | `[]` |
122123
| `skipDirectories` | Directories that should be excluded completely, i.e. not visible in the resulting data at all. The defaults will always be skipped. | `['/node_modules', '/flow-typed', '/coverage']` |
123124

124125
## Badges

generated/avg-maintainability.svg

Lines changed: 4 additions & 4 deletions
Loading

src/options.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ const baseOptions: CodehawkOptions = {
2525
default: ['/dist', '/bin', '/build'],
2626
replaceDefault: true,
2727
},
28+
excludeExact: {
29+
type: 'stringArray',
30+
default: [],
31+
replaceDefault: true,
32+
},
2833
excludeFilenames: {
2934
type: 'stringArray',
3035
default: ['.d.ts', '.min.js', '.bundle.js'],
@@ -60,9 +65,10 @@ const injectOptionValues = ({
6065
break
6166
case 'badgesDirectory':
6267
case 'excludeDirectories':
68+
case 'excludeExact':
6369
case 'excludeFilenames':
64-
case 'skipDirectories':
6570
case 'extensions':
71+
case 'skipDirectories':
6672
newOptions[optionKey] = val as string[]
6773
break
6874
case 'minimumThreshold':

src/types/codehawk.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// All option keys
22
type SupportedStringArrayKeys =
3-
| 'extensions'
3+
| 'badgesDirectory'
44
| 'excludeDirectories'
5+
| 'excludeExact'
56
| 'excludeFilenames'
7+
| 'extensions'
68
| 'skipDirectories'
7-
| 'badgesDirectory'
89
type SupportedBooleanOptions = 'enableFlow'
910
type SupportedNumberOptions = 'minimumThreshold'
1011

src/util.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { isBlocklisted } from './util'
22
import { buildOptions } from './options'
33

4-
const options = buildOptions({})
4+
const options = buildOptions({
5+
excludeExact: ['/src/foo/excluded.ts'],
6+
})
57

68
describe('util', () => {
79
describe('isBlocklisted', () => {
@@ -55,5 +57,12 @@ describe('util', () => {
5557
expect(isBlocklisted('/build/foo', 'index.ts', options)).toEqual(true)
5658
})
5759
})
60+
61+
describe('excludeExact', () => {
62+
it('excludes an exact match', () => {
63+
expect(isBlocklisted('/src/foo', 'bar.ts', options)).toEqual(false)
64+
expect(isBlocklisted('/src/foo', 'excluded.ts', options)).toEqual(true)
65+
})
66+
})
5867
})
5968
})

src/util.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const isBlocklisted = (
2323
filename: string,
2424
options: AssembledOptions
2525
): boolean => {
26-
const { excludeDirectories, excludeFilenames } = options
26+
const { excludeDirectories, excludeFilenames, excludeExact } = options
2727

2828
// Check for blocklisted directories
2929
for (let i = 0; i < excludeDirectories.length; i += 1) {
@@ -39,6 +39,13 @@ export const isBlocklisted = (
3939
}
4040
}
4141

42+
// Check for exact matches
43+
for (let i = 0; i < excludeExact.length; i += 1) {
44+
if (excludeExact[i] === `${relativeDir}/${filename}`) {
45+
return true
46+
}
47+
}
48+
4249
return false
4350
}
4451

0 commit comments

Comments
 (0)