Skip to content

Commit

Permalink
chore: enforce consistent-type-imports (#4891)
Browse files Browse the repository at this point in the history
  • Loading branch information
cardoso authored Nov 19, 2024
1 parent 5928fe5 commit fbdc834
Show file tree
Hide file tree
Showing 141 changed files with 471 additions and 497 deletions.
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default tseslint.config(
rules: {
// Rules without config, sorted alphabetically by namespace, then rule
'@lwc/lwc-internal/no-invalid-todo': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-base-to-string': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { types, Visitor } from '@babel/core';
import { LWC_VERSION_COMMENT } from '@lwc/shared';
import { BabelAPI, LwcBabelPluginPass } from './types';
import type { types, Visitor } from '@babel/core';
import type { BabelAPI, LwcBabelPluginPass } from './types';

export default function compilerVersionNumber({ types: t }: BabelAPI): Visitor<LwcBabelPluginPass> {
return {
Expand Down
8 changes: 4 additions & 4 deletions packages/@lwc/babel-plugin-component/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { basename, extname } from 'path';
import * as types from '@babel/types';
import { addDefault, addNamed } from '@babel/helper-module-imports';
import { NodePath } from '@babel/traverse';
import { Visitor } from '@babel/core';
import { generateCustomElementTagName, getAPIVersionFromNumber } from '@lwc/shared';
import {
COMPONENT_NAME_KEY,
Expand All @@ -18,7 +15,10 @@ import {
API_VERSION_KEY,
COMPONENT_CLASS_ID,
} from './constants';
import { BabelAPI, BabelTypes, LwcBabelPluginPass } from './types';
import type * as types from '@babel/types';
import type { NodePath } from '@babel/traverse';
import type { Visitor } from '@babel/core';
import type { BabelAPI, BabelTypes, LwcBabelPluginPass } from './types';

function getBaseName(classPath: string) {
const ext = extname(classPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { LWC_PACKAGE_EXPORTS } from '../../constants';
import { DecoratorMeta } from '../index';
import type { DecoratorMeta } from '../index';

const { API_DECORATOR } = LWC_PACKAGE_EXPORTS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { types } from '@babel/core';
import { NodePath } from '@babel/traverse';
import { DECORATOR_TYPES, LWC_COMPONENT_PROPERTIES } from '../../constants';
import { DecoratorMeta } from '../index';
import { BabelTypes } from '../../types';
import { ClassBodyItem } from '../types';
import { isApiDecorator } from './shared';
import type { types } from '@babel/core';
import type { NodePath } from '@babel/traverse';
import type { DecoratorMeta } from '../index';
import type { BabelTypes } from '../../types';
import type { ClassBodyItem } from '../types';

const { PUBLIC_PROPS, PUBLIC_METHODS } = LWC_COMPONENT_PROPERTIES;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { DecoratorErrors } from '@lwc/errors';
import { NodePath } from '@babel/traverse';
import { types } from '@babel/core';
import { generateError } from '../../utils';
import { LwcBabelPluginPass } from '../../types';
import {
AMBIGUOUS_PROP_SET,
DECORATOR_TYPES,
DISALLOWED_PROP_SET,
LWC_PACKAGE_EXPORTS,
} from '../../constants';
import { DecoratorMeta } from '../index';
import { isApiDecorator } from './shared';
import type { NodePath } from '@babel/traverse';
import type { types } from '@babel/core';
import type { LwcBabelPluginPass } from '../../types';
import type { DecoratorMeta } from '../index';

const { TRACK_DECORATOR } = LWC_PACKAGE_EXPORTS;

Expand Down
8 changes: 4 additions & 4 deletions packages/@lwc/babel-plugin-component/src/decorators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { Node, types, Visitor } from '@babel/core';
import { Binding, NodePath } from '@babel/traverse';
import { addNamed } from '@babel/helper-module-imports';
import { DecoratorErrors } from '@lwc/errors';
import { APIFeature, getAPIVersionFromNumber, isAPIFeatureEnabled } from '@lwc/shared';
import { DECORATOR_TYPES, LWC_PACKAGE_ALIAS, REGISTER_DECORATORS_ID } from '../constants';
import { generateError, isClassMethod, isGetterClassMethod, isSetterClassMethod } from '../utils';
import { BabelAPI, BabelTypes, LwcBabelPluginPass } from '../types';
import api from './api';
import wire from './wire';
import track from './track';
import { ClassBodyItem, ImportSpecifier, LwcDecoratorName } from './types';
import type { BabelAPI, BabelTypes, LwcBabelPluginPass } from '../types';
import type { Binding, NodePath } from '@babel/traverse';
import type { Node, types, Visitor } from '@babel/core';
import type { ClassBodyItem, ImportSpecifier, LwcDecoratorName } from './types';

const DECORATOR_TRANSFORMS = [api, wire, track];
const AVAILABLE_DECORATORS = DECORATOR_TRANSFORMS.map((transform) => transform.name).join(', ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import { DecoratorErrors } from '@lwc/errors';
import { LWC_COMPONENT_PROPERTIES, LWC_PACKAGE_EXPORTS } from '../../constants';
import { generateError } from '../../utils';
import { BabelTypes, LwcBabelPluginPass } from '../../types';
import { DecoratorMeta } from '../index';
import type { BabelTypes, LwcBabelPluginPass } from '../../types';
import type { DecoratorMeta } from '../index';

const { TRACK_DECORATOR } = LWC_PACKAGE_EXPORTS;

Expand Down
8 changes: 4 additions & 4 deletions packages/@lwc/babel-plugin-component/src/decorators/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { NodePath } from '@babel/traverse';
import { types } from '@babel/core';
import { LWCErrorInfo } from '@lwc/errors';
import * as t from '@babel/types';
import type { NodePath } from '@babel/traverse';
import type { types } from '@babel/core';
import type { LWCErrorInfo } from '@lwc/errors';
import type * as t from '@babel/types';

export type ImportSpecifier = {
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { LWC_PACKAGE_EXPORTS } from '../../constants';
import { DecoratorMeta } from '../index';
import type { DecoratorMeta } from '../index';

const { WIRE_DECORATOR } = LWC_PACKAGE_EXPORTS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { types } from '@babel/core';
import { NodePath, Scope } from '@babel/traverse';
import { LWC_COMPONENT_PROPERTIES } from '../../constants';
import { DecoratorMeta } from '../index';
import { BabelTypes } from '../../types';
import { BindingOptions } from '../types';
import { isWireDecorator } from './shared';
import type { types } from '@babel/core';
import type { NodePath, Scope } from '@babel/traverse';
import type { DecoratorMeta } from '../index';
import type { BabelTypes } from '../../types';
import type { BindingOptions } from '../types';

const WIRE_PARAM_PREFIX = '$';
const WIRE_CONFIG_ARG_NAME = '$cmp';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { types } from '@babel/core';
import { NodePath } from '@babel/traverse';
import { DecoratorErrors } from '@lwc/errors';
import { LWC_PACKAGE_EXPORTS } from '../../constants';
import { generateError } from '../../utils';
import { LwcBabelPluginPass } from '../../types';
import { DecoratorMeta } from '../index';
import { isWireDecorator } from './shared';
import type { types } from '@babel/core';
import type { NodePath } from '@babel/traverse';
import type { LwcBabelPluginPass } from '../../types';
import type { DecoratorMeta } from '../index';

const { TRACK_DECORATOR, WIRE_DECORATOR, API_DECORATOR } = LWC_PACKAGE_EXPORTS;

Expand Down
6 changes: 3 additions & 3 deletions packages/@lwc/babel-plugin-component/src/dedupe-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import { types } from '@babel/core';
import { NodePath } from '@babel/traverse';
import { BabelAPI, BabelTypes } from './types';
import type { types } from '@babel/core';
import type { NodePath } from '@babel/traverse';
import type { BabelAPI, BabelTypes } from './types';

function defaultImport(
t: BabelTypes,
Expand Down
6 changes: 3 additions & 3 deletions packages/@lwc/babel-plugin-component/src/dynamic-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { NodePath } from '@babel/traverse';
import { types, Visitor } from '@babel/core';
import { addNamed } from '@babel/helper-module-imports';
import { CompilerMetrics, LWCClassErrors } from '@lwc/errors';
import { generateError, incrementMetricCounter } from './utils';
import { LwcBabelPluginPass } from './types';
import type { types, Visitor } from '@babel/core';
import type { NodePath } from '@babel/traverse';
import type { LwcBabelPluginPass } from './types';

function getImportSource(path: NodePath<types.Import>): NodePath<types.Node> {
return path.parentPath.get('arguments.0') as NodePath<types.Node>;
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/babel-plugin-component/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import dynamicImports from './dynamic-imports';
import scopeCssImports from './scope-css-imports';
import compilerVersionNumber from './compiler-version-number';
import { getEngineImportSpecifiers } from './utils';
import { BabelAPI, LwcBabelPluginPass } from './types';
import type { BabelAPI, LwcBabelPluginPass } from './types';
import type { PluginObj } from '@babel/core';

// This is useful for consumers of this package to define their options
Expand Down
6 changes: 3 additions & 3 deletions packages/@lwc/babel-plugin-component/src/scope-css-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

// Add ?scoped=true to any imports ending with .scoped.css. This signals that the stylesheet
// should be treated as "scoped".
import { Node } from '@babel/core';
import { NodePath } from '@babel/traverse';
import { BabelAPI } from './types';
import type { Node } from '@babel/core';
import type { NodePath } from '@babel/traverse';
import type { BabelAPI } from './types';

export default function ({ types: t }: BabelAPI, path: NodePath): void {
const programPath = path.isProgram() ? path : path.findParent((node) => node.isProgram());
Expand Down
6 changes: 3 additions & 3 deletions packages/@lwc/babel-plugin-component/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import * as BabelCoreNamespace from '@babel/core';
import { PluginPass, types } from '@babel/core';
import { InstrumentationObject } from '@lwc/errors';
import type * as BabelCoreNamespace from '@babel/core';
import type { PluginPass, types } from '@babel/core';
import type { InstrumentationObject } from '@lwc/errors';

export type BabelAPI = typeof BabelCoreNamespace;
export type BabelTypes = typeof types;
Expand Down
11 changes: 6 additions & 5 deletions packages/@lwc/babel-plugin-component/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import lineColumn from 'line-column';
import { types } from '@babel/core';
import { NodePath } from '@babel/traverse';
import { CompilerMetrics, generateErrorMessage } from '@lwc/errors';
import { generateErrorMessage } from '@lwc/errors';
import { LWC_PACKAGE_ALIAS } from './constants';
import { DecoratorErrorOptions, ImportSpecifier } from './decorators/types';
import { LwcBabelPluginPass } from './types';
import type { types } from '@babel/core';
import type { NodePath } from '@babel/traverse';
import type { CompilerMetrics } from '@lwc/errors';
import type { DecoratorErrorOptions, ImportSpecifier } from './decorators/types';
import type { LwcBabelPluginPass } from './types';

function isClassMethod(
classMethod: NodePath<types.Node>,
Expand Down
5 changes: 3 additions & 2 deletions packages/@lwc/compiler/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { InstrumentationObject, CompilerValidationErrors, invariant } from '@lwc/errors';
import { CompilerValidationErrors, invariant } from '@lwc/errors';
import { isUndefined, isBoolean, getAPIVersionFromNumber, DEFAULT_SSR_MODE } from '@lwc/shared';
import { CompilationMode } from '@lwc/ssr-compiler';
import type { InstrumentationObject } from '@lwc/errors';
import type { CompilationMode } from '@lwc/ssr-compiler';
import type { CustomRendererConfig } from '@lwc/template-compiler';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { describe, expect, it } from 'vitest';
import { TransformOptions } from '../../options';
import { transform } from '../transformer';
import type { TransformOptions } from '../../options';

const TRANSFORMATION_OPTIONS: TransformOptions = {
namespace: 'x',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/
import { vi, describe, it, expect } from 'vitest';
import { APIVersion, noop } from '@lwc/shared';
import { TransformOptions } from '../../options';
import { transformSync } from '../transformer';
import type { TransformOptions } from '../../options';

const TRANSFORMATION_OPTIONS: TransformOptions = {
namespace: 'x',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/
import { vi, describe, it, expect } from 'vitest';
import { noop } from '@lwc/shared';
import { TransformOptions } from '../../options';
import { transform, transformSync } from '../transformer';
import type { TransformOptions } from '../../options';

const TRANSFORMATION_OPTIONS: TransformOptions = {
namespace: 'x',
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/compiler/src/transformers/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { CompilerDiagnostic } from '@lwc/errors';
import type { CompilerDiagnostic } from '@lwc/errors';

/** The object returned after transforming code. */
export interface TransformResult {
Expand Down
3 changes: 2 additions & 1 deletion packages/@lwc/compiler/src/transformers/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import { isString } from '@lwc/shared';
import { TransformerErrors, generateCompilerError, invariant } from '@lwc/errors';
import { compileComponentForSSR, compileTemplateForSSR } from '@lwc/ssr-compiler';

import { NormalizedTransformOptions, TransformOptions, validateTransformOptions } from '../options';
import { validateTransformOptions } from '../options';
import styleTransform from './style';
import templateTransformer from './template';
import scriptTransformer from './javascript';
import type { NormalizedTransformOptions, TransformOptions } from '../options';
import type { TransformResult } from './shared';

/**
Expand Down
16 changes: 10 additions & 6 deletions packages/@lwc/engine-core/src/framework/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@ import { invokeEventListener } from './invoker';
import { getVMBeingRendered, setVMBeingRendered } from './template';
import { EmptyArray } from './utils';
import { isComponentConstructor } from './def';
import { RenderMode, ShadowMode, SlotSet, VM } from './vm';
import { LightningElementConstructor } from './base-lightning-element';
import { RenderMode, ShadowMode } from './vm';
import { markAsDynamicChildren } from './rendering';
import {
isVBaseElement,
isVCustomElement,
isVScopedSlotFragment,
isVStatic,
VNodeType,
VStaticPartType,
} from './vnodes';
import { getComponentRegisteredName } from './component';
import { createSanitizedHtmlContent } from './sanitized-html-content';
import type { SanitizedHtmlContent } from './sanitized-html-content';
import type {
Key,
MutableVNodes,
VComment,
Expand All @@ -51,16 +57,14 @@ import {
VFragment,
VNode,
VNodes,
VNodeType,
VScopedSlotFragment,
VStatic,
VStaticPart,
VStaticPartData,
VStaticPartType,
VText,
} from './vnodes';
import { getComponentRegisteredName } from './component';
import { createSanitizedHtmlContent, SanitizedHtmlContent } from './sanitized-html-content';
import type { LightningElementConstructor } from './base-lightning-element';
import type { SlotSet, VM } from './vm';

const SymbolIterator: typeof Symbol.iterator = Symbol.iterator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { getAssociatedVM } from './vm';
import { getReadOnlyProxy } from './membrane';
import { HTMLElementConstructor, HTMLElementPrototype } from './html-element';
import { HTMLElementOriginalDescriptors } from './html-properties';
import { LightningElement } from './base-lightning-element';
import type { LightningElement } from './base-lightning-element';

// A bridge descriptor is a descriptor whose job is just to get the component instance
// from the element instance, and get the value or set a new value on the component.
Expand Down
Loading

0 comments on commit fbdc834

Please sign in to comment.