Skip to content

Commit

Permalink
feat(builder): add cacheStrategy option
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelss95 committed May 29, 2021
1 parent 9c861dc commit 46c96a9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/builder/src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface Schema extends JsonObject {
fix: boolean;
cache: boolean;
cacheLocation: string | null;
cacheStrategy: 'content' | 'metadata' | null;
eslintConfig: string | null;
ignorePath: string | null;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/builder/src/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
"type": "string",
"description": "Path to the cache file or directory."
},
"cacheStrategy":{
"type": "string",
"description": "Strategy to use for detecting changed files in the cache.",
"default": "metadata",
"enum": ["metadata", "content"]
},
"force": {
"type": "boolean",
"description": "Succeeds even if there was linting errors.",
Expand Down
9 changes: 5 additions & 4 deletions packages/builder/src/utils/eslint-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ export async function lint(
const eslint = new projectESLint.ESLint({
useEslintrc: true,
overrideConfigFile: eslintConfigPath,
ignorePath: options.ignorePath || undefined,
fix: !!options.fix,
cache: !!options.cache,
cacheLocation: options.cacheLocation || undefined,
ignorePath: options.ignorePath ?? undefined,
fix: options.fix,
cache: options.cache,
cacheLocation: options.cacheLocation ?? undefined,
cacheStrategy: options.cacheStrategy ?? undefined,
/**
* Default is `true` and if not overridden the eslint.lintFiles() method will throw an error
* when no target files are found.
Expand Down
4 changes: 3 additions & 1 deletion packages/builder/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { Architect } from '@angular-devkit/architect';
import { TestingArchitectHost } from '@angular-devkit/architect/testing';
import { logging, schema, json } from '@angular-devkit/core';
import { json, logging, schema } from '@angular-devkit/core';
import type { ESLint } from 'eslint';
import { resolve } from 'path';
import type { Schema } from '../src/schema';
Expand Down Expand Up @@ -60,6 +60,7 @@ function createValidRunBuilderOptions(
fix: true,
cache: true,
cacheLocation: 'cacheLocation1',
cacheStrategy: 'content',
format: 'stylish',
force: false,
quiet: false,
Expand Down Expand Up @@ -146,6 +147,7 @@ describe('Linter Builder', () => {
quiet: false,
cache: true,
cacheLocation: 'cacheLocation1',
cacheStrategy: 'content',
format: 'stylish',
force: false,
silent: false,
Expand Down
14 changes: 8 additions & 6 deletions packages/builder/tests/utils/eslint-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,39 @@ describe('eslint-utils', () => {
});

it('should create the ESLint instance with the proper parameters', async () => {
await lint('/root', './.eslintrc.json', <unknown>{
await lint('/root', './.eslintrc.json', {
fix: true,
cache: true,
cacheLocation: '/root/cache',
// eslint-disable-next-line @typescript-eslint/no-empty-function
}).catch(() => {});
cacheStrategy: 'content',
}).catch();

expect(ESLint).toHaveBeenCalledWith({
overrideConfigFile: './.eslintrc.json',
fix: true,
cache: true,
cacheLocation: '/root/cache',
cacheStrategy: 'content',
ignorePath: undefined,
useEslintrc: true,
errorOnUnmatchedPattern: false,
});
});

it('should create the ESLint instance with the proper parameters', async () => {
await lint('/root', undefined, <unknown>{
await lint('/root', undefined, {
fix: true,
cache: true,
cacheLocation: '/root/cache',
// eslint-disable-next-line @typescript-eslint/no-empty-function
}).catch(() => {});
cacheStrategy: 'content',
}).catch();

expect(ESLint).toHaveBeenCalledWith({
overrideConfigFile: undefined,
fix: true,
cache: true,
cacheLocation: '/root/cache',
cacheStrategy: 'content',
ignorePath: undefined,
useEslintrc: true,
errorOnUnmatchedPattern: false,
Expand Down

0 comments on commit 46c96a9

Please sign in to comment.