Skip to content

Commit ff9557d

Browse files
authored
feat(builder): add rulesdir option (#589)
1 parent 4b150bf commit ff9557d

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

packages/builder/src/lint.impl.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function createValidRunBuilderOptions(
7070
ignorePath: null,
7171
outputFile: null,
7272
noEslintrc: false,
73+
rulesdir: [],
7374
...additionalOptions,
7475
};
7576
}
@@ -147,6 +148,7 @@ describe('Linter Builder', () => {
147148
outputFile: null,
148149
ignorePath: null,
149150
noEslintrc: false,
151+
rulesdir: [],
150152
}),
151153
mockContext,
152154
);
@@ -169,6 +171,7 @@ describe('Linter Builder', () => {
169171
outputFile: null,
170172
ignorePath: null,
171173
noEslintrc: false,
174+
rulesdir: [],
172175
},
173176
);
174177
});

packages/builder/src/schema.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface Schema extends JsonObject {
1515
ignorePath: string | null;
1616
outputFile: string | null;
1717
noEslintrc: boolean;
18+
rulesdir: string[];
1819
}
1920

2021
type Formatter =

packages/builder/src/schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@
9393
"type": "boolean",
9494
"description": "The equivalent of the --no-eslintrc flag on the ESLint CLI, it is false by default",
9595
"default": false
96+
},
97+
"rulesdir": {
98+
"type": "array",
99+
"description": "The equivalent of the --rulesdir flag on the ESLint CLI, it is an empty array by default",
100+
"default": [],
101+
"items": {
102+
"type": "string"
103+
}
96104
}
97105
},
98106
"additionalProperties": false,

packages/builder/src/utils/eslint-utils.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe('eslint-utils', () => {
3737
ignorePath: undefined,
3838
useEslintrc: true,
3939
errorOnUnmatchedPattern: false,
40+
rulePaths: [],
4041
});
4142
});
4243

@@ -58,6 +59,7 @@ describe('eslint-utils', () => {
5859
ignorePath: undefined,
5960
useEslintrc: true,
6061
errorOnUnmatchedPattern: false,
62+
rulePaths: [],
6163
});
6264
});
6365

@@ -79,6 +81,32 @@ describe('eslint-utils', () => {
7981
ignorePath: undefined,
8082
useEslintrc: false,
8183
errorOnUnmatchedPattern: false,
84+
rulePaths: [],
85+
});
86+
});
87+
});
88+
89+
describe('rulesdir', () => {
90+
it('should create the ESLint instance with "rulePaths" set to the given value for rulesdir', async () => {
91+
const extraRuleDirectories = ['./some-rules', '../some-more-rules'];
92+
await lint('/root', undefined, {
93+
fix: true,
94+
cache: true,
95+
cacheLocation: '/root/cache',
96+
cacheStrategy: 'content',
97+
rulesdir: extraRuleDirectories,
98+
// eslint-disable-next-line @typescript-eslint/no-empty-function
99+
}).catch(() => {});
100+
101+
expect(ESLint).toHaveBeenCalledWith({
102+
fix: true,
103+
cache: true,
104+
cacheLocation: '/root/cache',
105+
cacheStrategy: 'content',
106+
ignorePath: undefined,
107+
useEslintrc: true,
108+
errorOnUnmatchedPattern: false,
109+
rulePaths: extraRuleDirectories,
82110
});
83111
});
84112
});

packages/builder/src/utils/eslint-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export async function lint(
3131
cache: !!options.cache,
3232
cacheLocation: options.cacheLocation || undefined,
3333
cacheStrategy: options.cacheStrategy || undefined,
34+
rulePaths: options.rulesdir || [],
3435
/**
3536
* Default is `true` and if not overridden the eslint.lintFiles() method will throw an error
3637
* when no target files are found.

0 commit comments

Comments
 (0)