feat(linter): add cacheStrategy, rulesdir and resolvePluginsRelativeTo flags to eslint executor (#9709)
This commit is contained in:
parent
9562ad2bab
commit
a64bba9980
@ -282,6 +282,22 @@
|
|||||||
"hasTypeAwareRules": {
|
"hasTypeAwareRules": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "When set to `true`, the linter will invalidate its cache when any of its dependencies changes."
|
"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,
|
"additionalProperties": false,
|
||||||
|
|||||||
@ -45,6 +45,7 @@ function createValidRunBuilderOptions(
|
|||||||
fix: true,
|
fix: true,
|
||||||
cache: true,
|
cache: true,
|
||||||
cacheLocation: 'cacheLocation1',
|
cacheLocation: 'cacheLocation1',
|
||||||
|
cacheStrategy: 'content',
|
||||||
format: 'stylish',
|
format: 'stylish',
|
||||||
force: false,
|
force: false,
|
||||||
silent: false,
|
silent: false,
|
||||||
@ -54,6 +55,8 @@ function createValidRunBuilderOptions(
|
|||||||
noEslintrc: false,
|
noEslintrc: false,
|
||||||
quiet: false,
|
quiet: false,
|
||||||
hasTypeAwareRules: false,
|
hasTypeAwareRules: false,
|
||||||
|
rulesdir: [],
|
||||||
|
resolvePluginsRelativeTo: null,
|
||||||
...additionalOptions,
|
...additionalOptions,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -137,6 +140,7 @@ describe('Linter Builder', () => {
|
|||||||
fix: true,
|
fix: true,
|
||||||
cache: true,
|
cache: true,
|
||||||
cacheLocation: 'cacheLocation1',
|
cacheLocation: 'cacheLocation1',
|
||||||
|
cacheStrategy: 'content',
|
||||||
format: 'stylish',
|
format: 'stylish',
|
||||||
force: false,
|
force: false,
|
||||||
silent: false,
|
silent: false,
|
||||||
@ -145,6 +149,8 @@ describe('Linter Builder', () => {
|
|||||||
outputFile: null,
|
outputFile: null,
|
||||||
quiet: false,
|
quiet: false,
|
||||||
noEslintrc: false,
|
noEslintrc: false,
|
||||||
|
rulesdir: [],
|
||||||
|
resolvePluginsRelativeTo: null,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,9 @@ export interface Schema extends JsonObject {
|
|||||||
quiet: boolean;
|
quiet: boolean;
|
||||||
ignorePath: string | null;
|
ignorePath: string | null;
|
||||||
hasTypeAwareRules: boolean;
|
hasTypeAwareRules: boolean;
|
||||||
|
cacheStrategy: 'content' | 'metadata' | null;
|
||||||
|
rulesdir: string[];
|
||||||
|
resolvePluginsRelativeTo: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
type Formatter =
|
type Formatter =
|
||||||
|
|||||||
@ -94,6 +94,24 @@
|
|||||||
"hasTypeAwareRules": {
|
"hasTypeAwareRules": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "When set to `true`, the linter will invalidate its cache when any of its dependencies changes."
|
"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,
|
"additionalProperties": false,
|
||||||
|
|||||||
@ -22,6 +22,7 @@ describe('eslint-utils', () => {
|
|||||||
fix: true,
|
fix: true,
|
||||||
cache: true,
|
cache: true,
|
||||||
cacheLocation: '/root/cache',
|
cacheLocation: '/root/cache',
|
||||||
|
cacheStrategy: 'content',
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
|
|
||||||
expect(ESLint).toHaveBeenCalledWith({
|
expect(ESLint).toHaveBeenCalledWith({
|
||||||
@ -29,8 +30,11 @@ describe('eslint-utils', () => {
|
|||||||
fix: true,
|
fix: true,
|
||||||
cache: true,
|
cache: true,
|
||||||
cacheLocation: '/root/cache',
|
cacheLocation: '/root/cache',
|
||||||
|
cacheStrategy: 'content',
|
||||||
ignorePath: undefined,
|
ignorePath: undefined,
|
||||||
useEslintrc: true,
|
useEslintrc: true,
|
||||||
|
resolvePluginsRelativeTo: undefined,
|
||||||
|
rulePaths: [],
|
||||||
errorOnUnmatchedPattern: false,
|
errorOnUnmatchedPattern: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -40,6 +44,7 @@ describe('eslint-utils', () => {
|
|||||||
fix: true,
|
fix: true,
|
||||||
cache: true,
|
cache: true,
|
||||||
cacheLocation: '/root/cache',
|
cacheLocation: '/root/cache',
|
||||||
|
cacheStrategy: 'content',
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
|
|
||||||
expect(ESLint).toHaveBeenCalledWith({
|
expect(ESLint).toHaveBeenCalledWith({
|
||||||
@ -47,8 +52,11 @@ describe('eslint-utils', () => {
|
|||||||
fix: true,
|
fix: true,
|
||||||
cache: true,
|
cache: true,
|
||||||
cacheLocation: '/root/cache',
|
cacheLocation: '/root/cache',
|
||||||
|
cacheStrategy: 'content',
|
||||||
ignorePath: undefined,
|
ignorePath: undefined,
|
||||||
useEslintrc: true,
|
useEslintrc: true,
|
||||||
|
resolvePluginsRelativeTo: undefined,
|
||||||
|
rulePaths: [],
|
||||||
errorOnUnmatchedPattern: false,
|
errorOnUnmatchedPattern: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -67,8 +75,62 @@ describe('eslint-utils', () => {
|
|||||||
fix: true,
|
fix: true,
|
||||||
cache: true,
|
cache: true,
|
||||||
cacheLocation: '/root/cache',
|
cacheLocation: '/root/cache',
|
||||||
|
cacheStrategy: undefined,
|
||||||
ignorePath: undefined,
|
ignorePath: undefined,
|
||||||
useEslintrc: false,
|
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',
|
||||||
|
cacheStrategy: 'content',
|
||||||
|
rulesdir: extraRuleDirectories,
|
||||||
|
}).catch(() => {});
|
||||||
|
|
||||||
|
expect(ESLint).toHaveBeenCalledWith({
|
||||||
|
overrideConfigFile: undefined,
|
||||||
|
fix: true,
|
||||||
|
cache: true,
|
||||||
|
cacheLocation: '/root/cache',
|
||||||
|
cacheStrategy: 'content',
|
||||||
|
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',
|
||||||
|
cacheStrategy: 'content',
|
||||||
|
resolvePluginsRelativeTo: './some-path',
|
||||||
|
}).catch(() => {});
|
||||||
|
|
||||||
|
expect(ESLint).toHaveBeenCalledWith({
|
||||||
|
overrideConfigFile: undefined,
|
||||||
|
fix: true,
|
||||||
|
cache: true,
|
||||||
|
cacheLocation: '/root/cache',
|
||||||
|
cacheStrategy: 'content',
|
||||||
|
ignorePath: undefined,
|
||||||
|
useEslintrc: true,
|
||||||
|
resolvePluginsRelativeTo: './some-path',
|
||||||
|
rulePaths: [],
|
||||||
errorOnUnmatchedPattern: false,
|
errorOnUnmatchedPattern: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -28,6 +28,9 @@ export async function lint(
|
|||||||
fix: !!options.fix,
|
fix: !!options.fix,
|
||||||
cache: !!options.cache,
|
cache: !!options.cache,
|
||||||
cacheLocation: options.cacheLocation || undefined,
|
cacheLocation: options.cacheLocation || undefined,
|
||||||
|
cacheStrategy: options.cacheStrategy || undefined,
|
||||||
|
resolvePluginsRelativeTo: options.resolvePluginsRelativeTo || undefined,
|
||||||
|
rulePaths: options.rulesdir || [],
|
||||||
/**
|
/**
|
||||||
* Default is `true` and if not overridden the eslint.lintFiles() method will throw an error
|
* Default is `true` and if not overridden the eslint.lintFiles() method will throw an error
|
||||||
* when no target files are found.
|
* when no target files are found.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user