mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[eslint/module-migration] add support for re-export defs and test rule (#102840)
Co-authored-by: spalger <spalger@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
d655c05ef0
commit
407b96e021
4 changed files with 84 additions and 3 deletions
|
@ -9,7 +9,7 @@
|
|||
const path = require('path');
|
||||
const KIBANA_ROOT = path.resolve(__dirname, '../../..');
|
||||
|
||||
function checkModuleNameNode(context, mappings, node) {
|
||||
function checkModuleNameNode(context, mappings, node, desc = 'Imported') {
|
||||
const mapping = mappings.find(
|
||||
(mapping) => mapping.from === node.value || node.value.startsWith(`${mapping.from}/`)
|
||||
);
|
||||
|
@ -42,7 +42,7 @@ function checkModuleNameNode(context, mappings, node) {
|
|||
}
|
||||
|
||||
context.report({
|
||||
message: `Imported module "${node.value}" should be "${newSource}"`,
|
||||
message: `${desc} module "${node.value}" should be "${newSource}"`,
|
||||
loc: node.loc,
|
||||
fix(fixer) {
|
||||
return fixer.replaceText(node, `'${newSource}'`);
|
||||
|
@ -101,6 +101,11 @@ module.exports = {
|
|||
ImportDeclaration(node) {
|
||||
checkModuleNameNode(context, mappings, node.source);
|
||||
},
|
||||
ExportNamedDeclaration(node) {
|
||||
if (node.source) {
|
||||
checkModuleNameNode(context, mappings, node.source, 'Re-exported');
|
||||
}
|
||||
},
|
||||
CallExpression(node) {
|
||||
if (
|
||||
node.callee.type === 'Identifier' &&
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
const { RuleTester } = require('eslint');
|
||||
const rule = require('./module_migration');
|
||||
const dedent = require('dedent');
|
||||
|
||||
const ruleTester = new RuleTester({
|
||||
parser: require.resolve('babel-eslint'),
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018,
|
||||
},
|
||||
});
|
||||
|
||||
ruleTester.run('@kbn/eslint/module-migration', rule, {
|
||||
valid: [
|
||||
{
|
||||
code: dedent`
|
||||
import "bar"
|
||||
require('bar')
|
||||
export { foo } from "bar"
|
||||
export const foo2 = 'bar'
|
||||
`,
|
||||
|
||||
options: [
|
||||
[
|
||||
{
|
||||
from: 'foo',
|
||||
to: 'bar',
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
invalid: [
|
||||
{
|
||||
code: dedent`
|
||||
import "foo"
|
||||
require('foo/foo2')
|
||||
export { foo } from 'foo'
|
||||
export const foo2 = 'bar'
|
||||
`,
|
||||
|
||||
options: [
|
||||
[
|
||||
{
|
||||
from: 'foo',
|
||||
to: 'bar',
|
||||
},
|
||||
],
|
||||
],
|
||||
errors: [
|
||||
{
|
||||
line: 1,
|
||||
message: 'Imported module "foo" should be "bar"',
|
||||
},
|
||||
{
|
||||
line: 2,
|
||||
message: 'Imported module "foo/foo2" should be "bar/foo2"',
|
||||
},
|
||||
{
|
||||
line: 3,
|
||||
message: 'Re-exported module "foo" should be "bar"',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
// eslint-disable-next-line @kbn/eslint/module_migration
|
||||
import { InjectedIntl as _InjectedIntl, InjectedIntlProps as _InjectedIntlProps } from 'react-intl';
|
||||
// eslint-disable-next-line @kbn/eslint/module_migration
|
||||
export type { InjectedIntl, InjectedIntlProps } from 'react-intl';
|
||||
|
||||
export {
|
||||
|
@ -20,7 +21,7 @@ export {
|
|||
FormattedMessage,
|
||||
FormattedHTMLMessage,
|
||||
// Only used for testing. Use I18nProvider otherwise.
|
||||
IntlProvider as __IntlProvider,
|
||||
IntlProvider as __IntlProvider, // eslint-disable-next-line @kbn/eslint/module_migration
|
||||
} from 'react-intl';
|
||||
|
||||
export { I18nProvider } from './provider';
|
||||
|
|
|
@ -12,4 +12,5 @@
|
|||
* More docs and examples can be found here https://github.com/yahoo/react-intl/wiki/API#injection-api
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line @kbn/eslint/module_migration
|
||||
export { injectIntl as injectI18n } from 'react-intl';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue