Skip to content

Commit

Permalink
chore: apply fix from last version of eslint-plugin-unicorn
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalexiei committed Nov 20, 2024
1 parent 9a4ee87 commit 8b6c09f
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
'eslint-plugin/report-message-format': 'error',
'eslint-plugin/require-meta-docs-description': [
'error',
{ pattern: '^(Enforce|Ensure|Prefer|Forbid).+\\.$' },
{ pattern: String.raw`^(Enforce|Ensure|Prefer|Forbid).+\.$` },
],
'eslint-plugin/require-meta-schema': 'error',
'eslint-plugin/require-meta-type': 'error',
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"eslint": "^8.57.0 || ^9.0.0"
},
"dependencies": {
"@typescript-eslint/scope-manager": "^8.1.0",
"@typescript-eslint/utils": "^8.1.0",
"debug": "^4.3.4",
"doctrine": "^3.0.0",
Expand Down Expand Up @@ -82,8 +83,8 @@
"@total-typescript/ts-reset": "^0.5.1",
"@types/debug": "^4.1.12",
"@types/doctrine": "^0.0.9",
"@types/eslint8.56": "npm:@types/eslint@^8.56.11",
"@types/eslint": "^9.6.1",
"@types/eslint8.56": "npm:@types/eslint@^8.56.11",
"@types/eslint9": "npm:@types/eslint@^9.6.1",
"@types/is-glob": "^4.0.4",
"@types/jest": "^29.5.12",
Expand All @@ -97,9 +98,7 @@
"cross-env": "^7.0.3",
"enhanced-resolve": "^5.16.0",
"escope": "^4.0.0",
"eslint8.56": "npm:eslint@^8.56.0",
"eslint": "^9.15.0",
"eslint9": "npm:eslint@^9.15.0",
"eslint-config-prettier": "^9.1.0",
"eslint-doc-generator": "^1.7.1",
"eslint-import-resolver-typescript": "^3.6.1",
Expand All @@ -112,6 +111,8 @@
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^56.0.1",
"eslint8.56": "npm:eslint@^8.56.0",
"eslint9": "npm:eslint@^9.15.0",
"hermes-eslint": "^0.23.1",
"jest": "^29.7.0",
"klaw-sync": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/rules/dynamic-import-chunkname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export = createRule<[Options?], MessageId>({
const {
importFunctions = [],
allowEmpty = false,
webpackChunknameFormat = '([0-9a-zA-Z-_/.]|\\[(request|index)\\])+',
webpackChunknameFormat = String.raw`([0-9a-zA-Z-_/.]|\[(request|index)\])+`,
} = context.options[0] || {}

const paddedCommentRegex = /^ (\S[\S\s]+\S) $/
Expand Down
3 changes: 2 additions & 1 deletion src/rules/no-default-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export = createRule({

ExportNamedDeclaration(node) {
for (const specifier of node.specifiers.filter(
specifier => getValue(specifier.exported) === 'default')) {
specifier => getValue(specifier.exported) === 'default',
)) {
const { loc } = sourceCode.getFirstTokens(node)[1] || {}
// @ts-expect-error - experimental parser type
if (specifier.type === 'ExportDefaultSpecifier') {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-duplicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ function hasCommentInsideNonSpecifiers(
// `node` (only inside). If there's a `{...}` part, look for comments before
// the `{`, but not before the `}` (hence the `+1`s).
const someTokens =
openBraceIndex >= 0 && closeBraceIndex >= 0
openBraceIndex !== -1 && closeBraceIndex !== -1
? [
...tokens.slice(1, openBraceIndex + 1),
...tokens.slice(closeBraceIndex + 1),
Expand Down
20 changes: 9 additions & 11 deletions src/rules/no-import-module-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ function getEntryPoint(context: RuleContext) {

function findScope(context: RuleContext, identifier: string) {
const { scopeManager } = context.sourceCode
return (
scopeManager?.scopes
// eslint-disable-next-line unicorn/prefer-spread
.slice()
.reverse()
.find(scope =>
scope.variables.some(variable =>
variable.identifiers.some(node => node.name === identifier),
),
)
)
return scopeManager?.scopes

.slice()
.reverse()
.find(scope =>
scope.variables.some(variable =>
variable.identifiers.some(node => node.name === identifier),
),
)
}

function findDefinition(objectScope: TSESLint.Scope.Scope, identifier: string) {
Expand Down
3 changes: 1 addition & 2 deletions src/rules/no-named-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export = createRule({
}

const someNamed = node.specifiers.some(
specifier => getValue(specifier.exported) !==
'default',
specifier => getValue(specifier.exported) !== 'default',
)
if (someNamed) {
context.report({ node, messageId: 'noAllowed' })
Expand Down
4 changes: 1 addition & 3 deletions src/rules/prefer-default-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ export = createRule<[Options?], MessageId>({
},

ExportSpecifier(node) {
if (
getValue(node.exported) === 'default'
) {
if (getValue(node.exported) === 'default') {
hasDefaultExport = true
} else {
specifierExportCount++
Expand Down
2 changes: 1 addition & 1 deletion src/utils/declared-scope.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ScopeType } from '@typescript-eslint/scope-manager'
import type { TSESTree } from '@typescript-eslint/utils'
import type { ScopeType } from '@typescript-eslint/scope-manager';

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

Expand Down
5 changes: 4 additions & 1 deletion src/utils/export-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ export class ExportMap {
}
}

function addNamespace(object: object, identifier: TSESTree.Identifier | TSESTree.StringLiteral) {
function addNamespace(
object: object,
identifier: TSESTree.Identifier | TSESTree.StringLiteral,
) {
const nsfn = getNamespace(getValue(identifier))
if (nsfn) {
Object.defineProperty(object, 'namespace', { get: nsfn })
Expand Down
2 changes: 1 addition & 1 deletion test/rules/no-unresolved.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function runResolverTests(resolver: 'node' | 'webpack') {
invalid: [
tInvalid({
code: 'import reallyfake from "./reallyfake/module"',
settings: { 'import-x/ignore': ['^\\./fake/'] },
settings: { 'import-x/ignore': [String.raw`^\./fake/`] },
errors: [createError('unresolved', './reallyfake/module')],
}),

Expand Down
2 changes: 1 addition & 1 deletion test/rules/order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,7 @@ ruleTester.run('order', rule, {
},
],
settings: {
'import-x/internal-regex': '^(a|b|c|d|e|f|g|h|i|j|k)(\\/|$)',
'import-x/internal-regex': String.raw`^(a|b|c|d|e|f|g|h|i|j|k)(\/|$)`,
},
errors: Array.from({ length: 11 }, () => ({
messageId: 'oneLineBetweenGroups',
Expand Down
10 changes: 6 additions & 4 deletions test/utils/import-type.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,21 +313,23 @@ describe('importType(name)', () => {
it('`isExternalModule` works with windows directory separator', () => {
const context = testContext()
expect(
isExternalModule('foo', 'E:\\path\\to\\node_modules\\foo', context),
isExternalModule('foo', String.raw`E:\path\to\node_modules\foo`, context),
).toBe(true)
expect(
isExternalModule(
'@foo/bar',
'E:\\path\\to\\node_modules\\@foo\\bar',
String.raw`E:\path\to\node_modules\@foo\bar`,
context,
),
).toBe(true)
expect(
isExternalModule(
'foo',
'E:\\path\\to\\node_modules\\foo',
String.raw`E:\path\to\node_modules\foo`,
testContext({
'import-x/external-module-folders': ['E:\\path\\to\\node_modules'],
'import-x/external-module-folders': [
String.raw`E:\path\to\node_modules`,
],
}),
),
).toBe(true)
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2420,7 +2420,7 @@
"@typescript-eslint/types" "5.62.0"
"@typescript-eslint/visitor-keys" "5.62.0"

"@typescript-eslint/[email protected]":
"@typescript-eslint/[email protected]", "@typescript-eslint/scope-manager@^8.1.0":
version "8.15.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-8.15.0.tgz#28a1a0f13038f382424f45a988961acaca38f7c6"
integrity sha512-QRGy8ADi4J7ii95xz4UoiymmmMd/zuy9azCaamnZ3FM8T5fZcex8UfJcjkiEZjJSztKfEBe3dZ5T/5RHAmw2mA==
Expand Down

0 comments on commit 8b6c09f

Please sign in to comment.