Skip to content

Commit

Permalink
chore: clean up eslint config (#558)
Browse files Browse the repository at this point in the history
* chore: remove extreneous lint rules and ignore statements

* chore: add rule to sort imports alphabetically
  • Loading branch information
mrstork authored May 30, 2024
1 parent 4ef70ce commit 9278d6e
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 102 deletions.
89 changes: 32 additions & 57 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,36 @@ module.exports = {
},
rules: {
'arrow-body-style': 'off',
'no-param-reassign': ['error', { props: false }],
'no-underscore-dangle': 'off',
'no-magic-numbers': 'off',
'n/prefer-global/process': 'off',
'unicorn/numeric-separators-style': 'off',
'unicorn/filename-case': ['error', { case: 'kebabCase' }],
'import/no-extraneous-dependencies': 'off',
'import/no-namespace': 'off',
'class-methods-use-this': 'off',
complexity: 'off',
'func-style': 'off',
'import/extensions': 'off',
'line-comment-position': 'off',
'max-depth': 'off',
'func-style': 'off',
'class-methods-use-this': 'off',
'promise/prefer-await-to-then': 'off',
'promise/prefer-await-to-callbacks': 'off',
'promise/catch-or-return': 'off',
'promise/always-return': 'off',
'max-lines': 'off',
'max-lines-per-function': 'off',
'max-nested-callbacks': 'off',
'max-statements': 'off',
'require-await': 'off',
'n/prefer-global/process': 'off',
'no-inline-comments': 'off',
'line-comment-position': 'off',
complexity: 'off',
'max-lines': 'off',
'no-magic-numbers': 'off',
'no-param-reassign': ['error', { props: false }],
'no-underscore-dangle': 'off',
'promise/always-return': 'off',
'promise/catch-or-return': 'off',
'promise/prefer-await-to-callbacks': 'off',
'promise/prefer-await-to-then': 'off',
'require-await': 'off',
'sort-imports': [
'error',
{
allowSeparatedGroups: true,
ignoreCase: true,
ignoreDeclarationSort: true,
},
],
'unicorn/filename-case': ['error', { case: 'kebabCase' }],
'unicorn/numeric-separators-style': 'off',
},
overrides: [
...overrides,
Expand All @@ -46,55 +53,23 @@ module.exports = {
'@typescript-eslint/no-floating-promises': 'error',
},
},
{
files: ['src/run/**'],
rules: {
'no-restricted-imports': [
'error',
{
paths: [
{
name: '@opentelemetry/api',
importNames: ['trace'],
message: 'Please use `getTracer()` from `./handlers/tracer.cjs` instead',
},
],
},
],
},
},
{
files: ['src/run/handlers/**'],
rules: {
'max-statements': ['error', 30],
'import/no-anonymous-default-export': 'off',
},
},
{
files: ['src/**/*.test.*'],
rules: {
'max-statements': 'off',
'max-lines-per-function': 'off',
},
},
{
files: ['src/build/**/*.ts'],
files: ['src/run/**'],
rules: {
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'path',
importNames: ['resolve'],
message:
'Please use `PluginContext.resolve` instead to comply with our monorepo support',
},
{
name: 'node:path',
importNames: ['resolve'],
message:
'Please use `PluginContext.resolve` instead to comply with our monorepo support',
name: '@opentelemetry/api',
importNames: ['trace'],
message: 'Please use `getTracer()` from `./handlers/tracer.cjs` instead',
},
],
},
Expand All @@ -104,10 +79,10 @@ module.exports = {
{
files: ['src/build/templates/**/*'],
rules: {
'n/no-missing-import': 'off',
'import/no-unresolved': 'off',
'import/no-anonymous-default-export': 'off',
'func-names': 'off',
'import/no-anonymous-default-export': 'off',
'import/no-unresolved': 'off',
'n/no-missing-import': 'off',
},
},
],
Expand Down
1 change: 0 additions & 1 deletion e2e-report/app/layout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/no-unassigned-import
import './globals.scss'

export const metadata = {
Expand Down
14 changes: 7 additions & 7 deletions edge-runtime/lib/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { Key } from '../vendor/deno.land/x/[email protected]/index.ts'
import { compile, pathToRegexp } from '../vendor/deno.land/x/[email protected]/index.ts'
import { getCookies } from '../vendor/deno.land/[email protected]/http/cookie.ts'

/*
/*
┌─────────────────────────────────────────────────────────────────────────┐
│ Inlined/re-implemented types │
└─────────────────────────────────────────────────────────────────────────┘
Expand Down Expand Up @@ -86,7 +86,7 @@ export type RoutesManifest = {
dynamicRoutes: DynamicRoute[]
}

/*
/*
┌─────────────────────────────────────────────────────────────────────────┐
│ packages/next/src/shared/lib/escape-regexp.ts │
└─────────────────────────────────────────────────────────────────────────┘
Expand All @@ -104,7 +104,7 @@ export function escapeStringRegexp(str: string) {
return str
}

/*
/*
┌─────────────────────────────────────────────────────────────────────────┐
│ packages/next/src/shared/lib/router/utils/querystring.ts │
└─────────────────────────────────────────────────────────────────────────┘
Expand All @@ -125,7 +125,7 @@ export function searchParamsToUrlQuery(searchParams: URLSearchParams): ParsedUrl
return query
}

/*
/*
┌─────────────────────────────────────────────────────────────────────────┐
│ packages/next/src/shared/lib/router/utils/parse-url.ts │
└─────────────────────────────────────────────────────────────────────────┘
Expand Down Expand Up @@ -156,7 +156,7 @@ export function parseUrl(url: string): ParsedUrl {
}
}

/*
/*
┌─────────────────────────────────────────────────────────────────────────┐
│ packages/next/src/shared/lib/router/utils/prepare-destination.ts │
│ — Changed to use WHATWG Fetch `Request` instead of │
Expand Down Expand Up @@ -392,7 +392,7 @@ function unescapeSegments(str: string) {
return str.replace(/__ESC_COLON_/gi, ':')
}

/*
/*
┌─────────────────────────────────────────────────────────────────────────┐
│ packages/next/src/shared/lib/router/utils/is-dynamic.ts │
└─────────────────────────────────────────────────────────────────────────┘
Expand All @@ -404,7 +404,7 @@ export function isDynamicRoute(route: string): boolean {
return TEST_ROUTE.test(route)
}

/*
/*
┌─────────────────────────────────────────────────────────────────────────┐
│ packages/next/shared/lib/router/utils/middleware-route-matcher.ts │
└─────────────────────────────────────────────────────────────────────────┘
Expand Down
2 changes: 1 addition & 1 deletion src/build/content/prerendered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { encodeBlobKey } from '../../shared/blobkey.js'
import type {
CachedFetchValue,
CachedPageValue,
NetlifyCacheHandlerValue,
NetlifyCachedRouteValue,
NetlifyCacheHandlerValue,
NetlifyIncrementalCacheValue,
} from '../../shared/cache-types.cjs'
import type { PluginContext } from '../plugin-context.js'
Expand Down
4 changes: 2 additions & 2 deletions src/build/content/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { readFile } from 'node:fs/promises'
import { join } from 'node:path'

import { NetlifyPluginOptions } from '@netlify/build'
import { expect, test, vi, describe, beforeEach } from 'vitest'
import { beforeEach, describe, expect, test, vi } from 'vitest'

import { mockFileSystem } from '../../../tests/index.js'
import { PluginContext, RequiredServerFilesManifest } from '../plugin-context.js'

import {
NextInternalModuleReplacement,
copyNextServerCode,
getPatchesToApply,
NextInternalModuleReplacement,
verifyHandlerDirStructure,
} from './server.js'

Expand Down
3 changes: 1 addition & 2 deletions src/build/content/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import {
access,
cp,
mkdir,
readFile,
readdir,
readFile,
readlink,
symlink,
writeFile,
} from 'node:fs/promises'
import { createRequire } from 'node:module'
// eslint-disable-next-line no-restricted-imports
import { dirname, join, resolve, sep } from 'node:path'
import { join as posixJoin, sep as posixSep } from 'node:path/posix'

Expand Down
2 changes: 1 addition & 1 deletion src/build/content/static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { inspect } from 'node:util'

import type { NetlifyPluginOptions } from '@netlify/build'
import glob from 'fast-glob'
import { Mock, beforeEach, describe, expect, test, vi } from 'vitest'
import { beforeEach, describe, expect, Mock, test, vi } from 'vitest'

import { mockFileSystem } from '../../../tests/index.js'
import { type FixtureTestContext } from '../../../tests/utils/contexts.js'
Expand Down
25 changes: 7 additions & 18 deletions src/build/image-cdn.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable id-length */
import type { NetlifyPluginOptions } from '@netlify/build'
import type { NextConfigComplete } from 'next/dist/server/config-shared.js'
import { TestContext, beforeEach, describe, expect, test } from 'vitest'
import { beforeEach, describe, expect, test, TestContext } from 'vitest'

import { setImageConfig } from './image-cdn.js'
import { PluginContext, type RequiredServerFilesManifest } from './plugin-context.js'
Expand Down Expand Up @@ -35,11 +34,8 @@ describe('Image CDN', () => {
expect.arrayContaining([
{
from: '/_next/image',
query: {
q: ':quality',
url: ':url',
w: ':width',
},
// eslint-disable-next-line id-length
query: { q: ':quality', url: ':url', w: ':width' },
to: '/.netlify/images?url=:url&w=:width&q=:quality',
status: 200,
},
Expand All @@ -64,11 +60,8 @@ describe('Image CDN', () => {
expect.arrayContaining([
{
from: '/_next/image',
query: {
q: ':quality',
url: ':url',
w: ':width',
},
// eslint-disable-next-line id-length
query: { q: ':quality', url: ':url', w: ':width' },
to: '/.netlify/images?url=:url&w=:width&q=:quality',
status: 200,
},
Expand Down Expand Up @@ -97,16 +90,12 @@ describe('Image CDN', () => {
expect.arrayContaining([
{
from: '/base/path/_custom/image/endpoint',
query: {
q: ':quality',
url: ':url',
w: ':width',
},
// eslint-disable-next-line id-length
query: { q: ':quality', url: ':url', w: ':width' },
to: '/.netlify/images?url=:url&w=:width&q=:quality',
status: 200,
},
]),
)
})
})
/* eslint-enable id-length */
2 changes: 0 additions & 2 deletions src/build/plugin-context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { existsSync, readFileSync } from 'node:fs'
import { readFile } from 'node:fs/promises'
// Here we need to actually import `resolve` from node:path as we want to resolve the paths
// eslint-disable-next-line no-restricted-imports
import { join, relative, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'

Expand Down
2 changes: 1 addition & 1 deletion src/run/handlers/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Context } from '@netlify/functions'
import type { NextConfigComplete } from 'next/dist/server/config-shared.js'
import type { WorkerRequestHandler } from 'next/dist/server/lib/types.js'

import { TagsManifest, getTagsManifest } from '../config.js'
import { getTagsManifest, TagsManifest } from '../config.js'
import {
adjustDateHeader,
setCacheControlHeaders,
Expand Down
4 changes: 2 additions & 2 deletions src/run/handlers/tracer.cts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Here we need to actually import `trace` from @opentelemetry/api to add extra wrappers
// other places should import `getTracer` from this module
// eslint-disable-next-line no-restricted-imports
import { trace, Tracer, Span } from '@opentelemetry/api'
import { Span, trace, Tracer } from '@opentelemetry/api'
import { SugaredTracer, wrapTracer } from '@opentelemetry/api/experimental'

import { RequestContext, getRequestContext } from './request-context.cjs'
import { getRequestContext, RequestContext } from './request-context.cjs'

const spanMeta = new WeakMap<Span, { start: number; name: string }>()
const spanCounter = new WeakMap<RequestContext, number>()
Expand Down
2 changes: 1 addition & 1 deletion src/shared/cache-types.cts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type {
IncrementalCache,
} from 'next/dist/server/lib/incremental-cache/index.js'
import type {
IncrementalCacheValue,
CachedRouteValue,
IncrementalCacheValue,
} from 'next/dist/server/response-cache/types.js'

export type {
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/simple-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ test.skip('streams stale responses', async ({ simple }) => {

const res = await fetch(path)

// eslint-disable-next-line no-loop-func
await new Promise<void>((resolve) => {
res.body?.pipeTo(
new WritableStream({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//@ts-check

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { composePlugins, withNx } = require('@nx/next')

/**
Expand Down
3 changes: 0 additions & 3 deletions tests/fixtures/nx-integrated/apps/next-app/next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//@ts-check

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { composePlugins, withNx } = require('@nx/next')

/**
Expand Down

0 comments on commit 9278d6e

Please sign in to comment.