Skip to content

Commit

Permalink
feat(builder): add rulesdir option (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry authored Jul 11, 2021
1 parent 4b150bf commit ff9557d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/builder/src/lint.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function createValidRunBuilderOptions(
ignorePath: null,
outputFile: null,
noEslintrc: false,
rulesdir: [],
...additionalOptions,
};
}
Expand Down Expand Up @@ -147,6 +148,7 @@ describe('Linter Builder', () => {
outputFile: null,
ignorePath: null,
noEslintrc: false,
rulesdir: [],
}),
mockContext,
);
Expand All @@ -169,6 +171,7 @@ describe('Linter Builder', () => {
outputFile: null,
ignorePath: null,
noEslintrc: false,
rulesdir: [],
},
);
});
Expand Down
1 change: 1 addition & 0 deletions packages/builder/src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface Schema extends JsonObject {
ignorePath: string | null;
outputFile: string | null;
noEslintrc: boolean;
rulesdir: string[];
}

type Formatter =
Expand Down
8 changes: 8 additions & 0 deletions packages/builder/src/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@
"type": "boolean",
"description": "The equivalent of the --no-eslintrc flag on the ESLint CLI, it is false by default",
"default": false
},
"rulesdir": {
"type": "array",
"description": "The equivalent of the --rulesdir flag on the ESLint CLI, it is an empty array by default",
"default": [],
"items": {
"type": "string"
}
}
},
"additionalProperties": false,
Expand Down
28 changes: 28 additions & 0 deletions packages/builder/src/utils/eslint-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('eslint-utils', () => {
ignorePath: undefined,
useEslintrc: true,
errorOnUnmatchedPattern: false,
rulePaths: [],
});
});

Expand All @@ -58,6 +59,7 @@ describe('eslint-utils', () => {
ignorePath: undefined,
useEslintrc: true,
errorOnUnmatchedPattern: false,
rulePaths: [],
});
});

Expand All @@ -79,6 +81,32 @@ describe('eslint-utils', () => {
ignorePath: undefined,
useEslintrc: false,
errorOnUnmatchedPattern: false,
rulePaths: [],
});
});
});

describe('rulesdir', () => {
it('should create the ESLint instance with "rulePaths" set to the given value for rulesdir', async () => {
const extraRuleDirectories = ['./some-rules', '../some-more-rules'];
await lint('/root', undefined, {
fix: true,
cache: true,
cacheLocation: '/root/cache',
cacheStrategy: 'content',
rulesdir: extraRuleDirectories,
// eslint-disable-next-line @typescript-eslint/no-empty-function
}).catch(() => {});

expect(ESLint).toHaveBeenCalledWith({
fix: true,
cache: true,
cacheLocation: '/root/cache',
cacheStrategy: 'content',
ignorePath: undefined,
useEslintrc: true,
errorOnUnmatchedPattern: false,
rulePaths: extraRuleDirectories,
});
});
});
Expand Down
1 change: 1 addition & 0 deletions packages/builder/src/utils/eslint-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function lint(
cache: !!options.cache,
cacheLocation: options.cacheLocation || undefined,
cacheStrategy: options.cacheStrategy || undefined,
rulePaths: options.rulesdir || [],
/**
* Default is `true` and if not overridden the eslint.lintFiles() method will throw an error
* when no target files are found.
Expand Down

0 comments on commit ff9557d

Please # to comment.