[eslint/module_migration] add exact option (#137000) (#137011)

(cherry picked from commit 703580f944)

Co-authored-by: Spencer <spencer@elastic.co>
This commit is contained in:
Kibana Machine 2022-07-22 19:09:02 -04:00 committed by GitHub
parent 187031607e
commit 1b7e51b683
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 1 deletions

View file

@ -12,7 +12,8 @@ const KIBANA_ROOT = findKibanaRoot();
function checkModuleNameNode(context, mappings, node, desc = 'Imported') {
const mapping = mappings.find(
(mapping) => mapping.from === node.value || node.value.startsWith(`${mapping.from}/`)
(mapping) =>
mapping.from === node.value || (!mapping.exact && node.value.startsWith(`${mapping.from}/`))
);
if (!mapping) {
@ -85,6 +86,10 @@ module.exports = {
exclude: {
type: 'array',
},
exact: {
type: 'boolean',
default: false,
},
},
anyOf: [
{

View file

@ -37,6 +37,21 @@ ruleTester.run('@kbn/eslint/module-migration', rule, {
],
],
},
{
code: dedent`
import "foo/bar"
`,
options: [
[
{
from: 'foo',
to: 'bar',
exact: true,
},
],
],
},
],
invalid: [
@ -148,5 +163,31 @@ ruleTester.run('@kbn/eslint/module-migration', rule, {
import '../../common/foo'
`,
},
{
code: dedent`
import 'foo'
import 'foo/bar'
`,
options: [
[
{
from: 'foo',
to: 'bar',
exact: true,
},
],
],
errors: [
{
line: 1,
message: 'Imported module "foo" should be "bar"',
},
],
output: dedent`
import 'bar'
import 'foo/bar'
`,
},
],
});