Skip to content

Commit

Permalink
refactor: remove method alias (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW authored Apr 4, 2024
1 parent 0a84314 commit 8b53954
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/rules/newline-after-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
import debug from 'debug'

import { isStaticRequire, createRule, getScope } from '../utils'
import { isStaticRequire, createRule } from '../utils'

const log = debug('eslint-plugin-import-x:rules:newline-after-import')

Expand Down Expand Up @@ -276,7 +276,7 @@ export = createRule<[Options?], MessageId>({
'Program:exit'(node) {
log('exit processing for', context.physicalFilename)

const scopeBody = getScopeBody(getScope(context, node))
const scopeBody = getScopeBody(context.sourceCode.getScope(node))

log('got scope:', scopeBody)

Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-amd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Rule to prefer imports to AMD
*/

import { createRule, getScope } from '../utils'
import { createRule } from '../utils'

type MessageId = 'amd'

Expand All @@ -23,7 +23,7 @@ export = createRule<[], MessageId>({
create(context) {
return {
CallExpression(node) {
if (getScope(context, node).type !== 'module') {
if (context.sourceCode.getScope(node).type !== 'module') {
return
}

Expand Down
10 changes: 5 additions & 5 deletions src/rules/no-commonjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import type { TSESLint, TSESTree } from '@typescript-eslint/utils'

import { createRule, getScope } from '../utils'
import { createRule } from '../utils'

type NormalizedOptions = {
allowPrimitiveModules?: boolean
Expand Down Expand Up @@ -127,16 +127,16 @@ export = createRule<[Options?], MessageId>({

// exports.
if ('name' in node.object && node.object.name === 'exports') {
const isInScope = getScope(context, node).variables.some(
variable => variable.name === 'exports',
)
const isInScope = context.sourceCode
.getScope(node)
.variables.some(variable => variable.name === 'exports')
if (!isInScope) {
context.report({ node, messageId: 'export' })
}
}
},
CallExpression(call) {
if (!validateScope(getScope(context, call))) {
if (!validateScope(context.sourceCode.getScope(call))) {
return
}

Expand Down
6 changes: 3 additions & 3 deletions src/rules/no-mutable-exports.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'

import { createRule, getScope } from '../utils'
import { createRule } from '../utils'

type MessageId = 'noMutable'

Expand Down Expand Up @@ -48,14 +48,14 @@ export = createRule<[], MessageId>({

return {
ExportDefaultDeclaration(node) {
const scope = getScope(context, node)
const scope = context.sourceCode.getScope(node)

if ('name' in node.declaration) {
checkDeclarationsInScope(scope, node.declaration.name)
}
},
ExportNamedDeclaration(node) {
const scope = getScope(context, node)
const scope = context.sourceCode.getScope(node)

if (node.declaration) {
checkDeclaration(node.declaration)
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
import { minimatch } from 'minimatch'

import { createRule, getScope } from '../utils'
import { createRule } from '../utils'

type MessageId = 'noNamespace'

Expand Down Expand Up @@ -59,7 +59,7 @@ export = createRule<[Options?], MessageId>({
return
}

const scopeVariables = getScope(context, node).variables
const scopeVariables = context.sourceCode.getScope(node).variables
const namespaceVariable = scopeVariables.find(
variable => variable.defs[0].node === node,
)!
Expand Down
4 changes: 1 addition & 3 deletions src/utils/declared-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import type { TSESTree } from '@typescript-eslint/utils'

import type { RuleContext } from '../types'

import { getScope } from './get-scope'

export function declaredScope(
context: RuleContext,
node: TSESTree.Node,
name: string,
) {
const references = getScope(context, node).references
const references = context.sourceCode.getScope(node).references
const reference = references.find(x => x.identifier.name === name)
if (!reference || !reference.resolved) {
return
Expand Down
6 changes: 0 additions & 6 deletions src/utils/get-ancestors.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/utils/get-scope.ts

This file was deleted.

4 changes: 1 addition & 3 deletions src/utils/import-declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import type { TSESTree } from '@typescript-eslint/utils'

import type { RuleContext } from '../types'

import { getAncestors } from './get-ancestors'

export const importDeclaration = (
context: RuleContext,
node: TSESTree.Node,
) => {
const ancestors = getAncestors(context, node)
const ancestors = context.sourceCode.getAncestors(node)
return ancestors[ancestors.length - 1] as TSESTree.ImportDeclaration
}
2 changes: 0 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ export * from './create-rule'
export * from './declared-scope'
export * from './docs-url'
export * from './export-map'
export * from './get-ancestors'
export * from './get-scope'
export * from './get-value'
export * from './hash'
export * from './ignore'
Expand Down

0 comments on commit 8b53954

Please sign in to comment.