Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(typescript-estree): requireimport = require() argument to be a string literal#9226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
import F = require(1 + 1);

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
import F = require(`1`);

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
import type { AST_NODE_TYPES } from '../../ast-node-types';
import type { BaseNode } from '../../base/BaseNode';
import type {Expression } from '../../unions/Expression';
import type {StringLiteral } from '../../expression/literal/StringLiteral/spec';

export interface TSExternalModuleReference extends BaseNode {
type: AST_NODE_TYPES.TSExternalModuleReference;
// TODO(#1852) - this must be a string
expression: Expression;
expression: StringLiteral;
}
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
import type { TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';

import { createRule } from '../util';

Expand DownExpand Up@@ -62,10 +61,7 @@ export default createRule({
node: TSESTree.TSExternalModuleReference,
): void {
const parent = node.parent as TSESTree.TSImportEqualsDeclaration;
if (
node.expression.type === AST_NODE_TYPES.Literal &&
node.expression.value === 'typescript'
) {
if (node.expression.value === 'typescript') {
context.report({
node,
messageId: 'noTSDefaultImport',
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -312,10 +312,7 @@ export default createRule<Options, MessageIds>({
node: TSESTree.TSImportEqualsDeclaration,
): void {
if (
node.moduleReference.type ===
AST_NODE_TYPES.TSExternalModuleReference &&
node.moduleReference.expression.type === AST_NODE_TYPES.Literal &&
typeof node.moduleReference.expression.value === 'string'
node.moduleReference.type === AST_NODE_TYPES.TSExternalModuleReference
) {
const synthesizedImport = {
...node,
Expand Down
15 changes: 0 additions & 15 deletionspackages/eslint-plugin/tests/rules/no-require-imports.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,10 +51,6 @@ require('remark-preset-prettier');
code: "import pkg = require('some-package');",
options: [{ allow: ['^some-package$'] }],
},
{
code: 'import pkg = require(`some-package`);',
options: [{ allow: ['^some-package$'] }],
},
],
invalid: [
{
Expand DownExpand Up@@ -207,16 +203,5 @@ var lib5 = require?.('lib5'),
},
],
},
{
code: 'import pkg = require(`./package.json`);',
options: [{ allow: ['^some-package$'] }],
errors: [
{
line: 1,
column: 14,
messageId: 'noRequireImports',
},
],
},
],
});
3 changes: 3 additions & 0 deletionspackages/typescript-estree/src/convert.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3107,6 +3107,9 @@ export class Converter {
);
}
case SyntaxKind.ExternalModuleReference: {
if (node.expression.kind !== SyntaxKind.StringLiteral) {
this.#throwError(node.expression, 'String literal expected.');
}
return this.createNode<TSESTree.TSExternalModuleReference>(node, {
type: AST_NODE_TYPES.TSExternalModuleReference,
expression: this.convertChild(node.expression),
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp