Skip to content

Commit

Permalink
feat(@typescript-eslint): enable new no-unsafe-<subject> rules
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Apr 7, 2020
1 parent 18332b9 commit fb70bb9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .eslintplugin/prefer-valid-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const isNameOfESLintConfigFile = (fname: string): boolean =>
configFiles.some(name => fname.endsWith(name));

const compileConfigCode = (fileCode: string): ESLint.Linter.Config =>
runInNewContext(fileCode, { module: { exports: {} }, require }) ?? {};
(runInNewContext(fileCode, { module: { exports: {} }, require }) ??
{}) as ESLint.Linter.Config;

const createCLIEngine = (config: ESLint.Linter.Config): ESLint.CLIEngine =>
new ESLint.CLIEngine({
Expand Down
3 changes: 3 additions & 0 deletions @typescript-eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ const config = {
],
'@typescript-eslint/no-unnecessary-qualifier': 'error',
'@typescript-eslint/no-unnecessary-type-arguments': 'error',
'@typescript-eslint/no-unsafe-call': 'error',
'@typescript-eslint/no-unsafe-member-access': 'error',
'@typescript-eslint/no-unsafe-return': 'error',
'@typescript-eslint/no-unused-expressions': 'error',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-use-before-define': [
Expand Down
12 changes: 7 additions & 5 deletions test/configs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ const configFiles = fs
)
.map(value => value.name);

const requireConfig = (config: string): Required<ESLint.Linter.Config> => ({
const requireConfig = (
config: string
): ESLint.Linter.Config &
Required<Pick<ESLint.Linter.Config, 'plugins' | 'extends' | 'rules'>> => ({
plugins: [],
extends: [],
rules: {},
// eslint-disable-next-line global-require,@typescript-eslint/no-require-imports
...require(config)
...(require(config) as Required<ESLint.Linter.Config>)
});

describe('package.json', () => {
Expand All @@ -35,9 +39,7 @@ describe('package.json', () => {

describe('for each config file', () => {
describe.each(configFiles)('%s config', configFile => {
const config: Required<ESLint.Linter.Config> = requireConfig(
`./../${configFile}`
);
const config = requireConfig(`./../${configFile}`);

it('is valid', () => {
expect.hasAssertions();
Expand Down

0 comments on commit fb70bb9

Please sign in to comment.