Skip to content

Commit

Permalink
feat(linter): add cacheStrategy, rulesdir and resolvePluginsRelativeT…
Browse files Browse the repository at this point in the history
…o flags to eslint executor
  • Loading branch information
leosvelperez committed Apr 6, 2022
1 parent cf54cc9 commit 46cef35
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/generated/packages/linter.json
Expand Up @@ -282,6 +282,22 @@
"hasTypeAwareRules": {
"type": "boolean",
"description": "When set to `true`, the linter will invalidate its cache when any of its dependencies changes."
},
"cacheStrategy": {
"type": "string",
"description": "Strategy to use for detecting changed files in the cache.",
"default": "metadata",
"enum": ["metadata", "content"]
},
"rulesdir": {
"type": "array",
"description": "The equivalent of the `--rulesdir` flag on the ESLint CLI.",
"default": [],
"items": { "type": "string" }
},
"resolvePluginsRelativeTo": {
"type": "string",
"description": "The equivalent of the `--resolve-plugins-relative-to` flag on the ESLint CLI."
}
},
"additionalProperties": false,
Expand Down
6 changes: 6 additions & 0 deletions packages/linter/src/executors/eslint/lint.impl.spec.ts
Expand Up @@ -45,6 +45,7 @@ function createValidRunBuilderOptions(
fix: true,
cache: true,
cacheLocation: 'cacheLocation1',
cacheStrategy: 'metadata',
format: 'stylish',
force: false,
silent: false,
Expand All @@ -54,6 +55,8 @@ function createValidRunBuilderOptions(
noEslintrc: false,
quiet: false,
hasTypeAwareRules: false,
resolvePluginsRelativeTo: null,
rulesdir: [],
...additionalOptions,
};
}
Expand Down Expand Up @@ -137,6 +140,7 @@ describe('Linter Builder', () => {
fix: true,
cache: true,
cacheLocation: 'cacheLocation1',
cacheStrategy: 'metadata',
format: 'stylish',
force: false,
silent: false,
Expand All @@ -145,6 +149,8 @@ describe('Linter Builder', () => {
outputFile: null,
quiet: false,
noEslintrc: false,
resolvePluginsRelativeTo: null,
rulesdir: [],
});
});

Expand Down
3 changes: 3 additions & 0 deletions packages/linter/src/executors/eslint/schema.d.ts
Expand Up @@ -15,6 +15,9 @@ export interface Schema extends JsonObject {
quiet: boolean;
ignorePath: string | null;
hasTypeAwareRules: boolean;
cacheStrategy: 'content' | 'metadata' | null;
rulesdir: string[];
resolvePluginsRelativeTo: string | null;
}

type Formatter =
Expand Down
18 changes: 18 additions & 0 deletions packages/linter/src/executors/eslint/schema.json
Expand Up @@ -94,6 +94,24 @@
"hasTypeAwareRules": {
"type": "boolean",
"description": "When set to `true`, the linter will invalidate its cache when any of its dependencies changes."
},
"cacheStrategy": {
"type": "string",
"description": "Strategy to use for detecting changed files in the cache.",
"default": "metadata",
"enum": ["metadata", "content"]
},
"rulesdir": {
"type": "array",
"description": "The equivalent of the `--rulesdir` flag on the ESLint CLI.",
"default": [],
"items": {
"type": "string"
}
},
"resolvePluginsRelativeTo": {
"type": "string",
"description": "The equivalent of the `--resolve-plugins-relative-to` flag on the ESLint CLI."
}
},
"additionalProperties": false,
Expand Down
59 changes: 59 additions & 0 deletions packages/linter/src/executors/eslint/utility/eslint-utils.spec.ts
Expand Up @@ -29,8 +29,11 @@ describe('eslint-utils', () => {
fix: true,
cache: true,
cacheLocation: '/root/cache',
cacheStrategy: 'metadata',
ignorePath: undefined,
useEslintrc: true,
resolvePluginsRelativeTo: undefined,
rulePaths: [],
errorOnUnmatchedPattern: false,
});
});
Expand All @@ -40,15 +43,19 @@ describe('eslint-utils', () => {
fix: true,
cache: true,
cacheLocation: '/root/cache',
cacheStrategy: 'content',
}).catch(() => {});

expect(ESLint).toHaveBeenCalledWith({
overrideConfigFile: undefined,
fix: true,
cache: true,
cacheLocation: '/root/cache',
cacheStrategy: 'content',
ignorePath: undefined,
useEslintrc: true,
resolvePluginsRelativeTo: undefined,
rulePaths: [],
errorOnUnmatchedPattern: false,
});
});
Expand All @@ -67,8 +74,60 @@ describe('eslint-utils', () => {
fix: true,
cache: true,
cacheLocation: '/root/cache',
cacheStrategy: 'metadata',
ignorePath: undefined,
useEslintrc: false,
resolvePluginsRelativeTo: undefined,
rulePaths: [],
errorOnUnmatchedPattern: false,
});
});
});

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(undefined, {
fix: true,
cache: true,
cacheLocation: '/root/cache',
rulesdir: extraRuleDirectories,
}).catch(() => {});

expect(ESLint).toHaveBeenCalledWith({
overrideConfigFile: undefined,
fix: true,
cache: true,
cacheLocation: '/root/cache',
cacheStrategy: 'metadata',
ignorePath: undefined,
useEslintrc: true,
resolvePluginsRelativeTo: undefined,
rulePaths: extraRuleDirectories,
errorOnUnmatchedPattern: false,
});
});
});

describe('resolvePluginsRelativeTo', () => {
it('should create the ESLint instance with "resolvePluginsRelativeTo" set to the given value for resolvePluginsRelativeTo', async () => {
await lint(undefined, {
fix: true,
cache: true,
cacheLocation: '/root/cache',
resolvePluginsRelativeTo: './some-path',
}).catch(() => {});

expect(ESLint).toHaveBeenCalledWith({
overrideConfigFile: undefined,
fix: true,
cache: true,
cacheLocation: '/root/cache',
cacheStrategy: 'metadata',
ignorePath: undefined,
useEslintrc: true,
resolvePluginsRelativeTo: './some-path',
rulePaths: [],
errorOnUnmatchedPattern: false,
});
});
Expand Down
3 changes: 3 additions & 0 deletions packages/linter/src/executors/eslint/utility/eslint-utils.ts
Expand Up @@ -28,6 +28,9 @@ export async function lint(
fix: !!options.fix,
cache: !!options.cache,
cacheLocation: options.cacheLocation || undefined,
cacheStrategy: options.cacheStrategy ?? 'metadata',
rulePaths: options.rulesdir ?? [],
resolvePluginsRelativeTo: options.resolvePluginsRelativeTo ?? undefined,
/**
* 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 46cef35

Please sign in to comment.