Skip to content

Commit

Permalink
chore(lint): fixed all fixable errors, ignored those that cannot be f…
Browse files Browse the repository at this point in the history
…ixed
  • Loading branch information
svobik7 committed Nov 7, 2024
1 parent 8323a9d commit 39e6152
Show file tree
Hide file tree
Showing 20 changed files with 602 additions and 177 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
browser: true,
node: true,
},
ignorePatterns: ['examples/*', 'dist/*'],
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-require-imports
module.exports = require('./dist/index')
1 change: 1 addition & 0 deletions mock.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-require-imports
module.exports = require('./dist/mock')
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"scripts": {
"prepare": "husky",
"clean": "rm -rf dist || true",
"build": "yarn clean && yarn typecheck && yarn test && node esbuild.mjs && yarn build:types",
"build": "yarn clean && yarn typecheck && yarn test && node esbuild.mjs && yarn build:types && yarn lint",
"build:types": "yarn dts-bundle-generator --config ./dts.config.js",
"build:no-test": "node esbuild.mjs",
"build:coverage": "yarn clean && yarn typecheck && yarn test && node esbuild.mjs",
Expand Down Expand Up @@ -50,8 +50,8 @@
"@semantic-release/github": "^11.0.1",
"@semantic-release/npm": "^12.0.1",
"@semantic-release/release-notes-generator": "^14.0.1",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"@typescript-eslint/eslint-plugin": "^8.13.0",
"@typescript-eslint/parser": "^8.13.0",
"@vitest/coverage-istanbul": "^2.0.4",
"arg": "^5.0.2",
"colors": "^1.4.0",
Expand All @@ -61,10 +61,10 @@
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-simple-import-sort": "^12.0.0",
"eslint-plugin-unused-imports": "^3.0.0",
"eslint-plugin-unused-imports": "^4.1.4",
"husky": "^9.0.7",
"lint-staged": "^15.2.10",
"prettier": "^3.2.4",
Expand Down
1 change: 1 addition & 0 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const cliDefaultParams: CliParams = {
packageDir: path.join(process.cwd(), `node_modules/${PKG_NAME}`),
}

// eslint-disable-next-line @typescript-eslint/no-require-imports
const cliFileParams = require(path.join(process.cwd(), cfgPath))
const cliParams: CliParams = {
...cliDefaultParams,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getPattern, type CompileFn, type DecoratorParams } from '../tpl-utils'
import { type CompileFn, type DecoratorParams, getPattern } from '../tpl-utils'

export const PATTERNS = {
originPath: getPattern('originPath'),
Expand Down
8 changes: 6 additions & 2 deletions src/cli/templates/decorators/with-layout-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { Rewrite } from '~/cli/types'
import { isTypedRewrite } from '~/utils/rewrite-utils'
import type { CompileFn, DecoratorParams } from '../tpl-utils'
import { getPattern, removePropTypes } from '../tpl-utils'
import {
type CompileFn,
type DecoratorParams,
getPattern,
removePropTypes,
} from '../tpl-utils'

export const PATTERNS = {
originPath: getPattern('originPath'),
Expand Down
7 changes: 6 additions & 1 deletion src/cli/templates/decorators/with-layout-viewport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { Rewrite } from '~/cli/types'
import { isTypedRewrite } from '~/utils/rewrite-utils'
import { getPattern, removePropTypes ,type CompileFn,type DecoratorParams } from '../tpl-utils';
import {
type CompileFn,
type DecoratorParams,
getPattern,
removePropTypes,
} from '../tpl-utils'

export const PATTERNS = {
originPath: getPattern('originPath'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getPattern ,type CompileFn,type DecoratorParams } from '../tpl-utils';
import { type CompileFn, type DecoratorParams, getPattern } from '../tpl-utils'

export const PATTERNS = {
originPath: getPattern('originPath'),
Expand Down
8 changes: 6 additions & 2 deletions src/cli/templates/decorators/with-page-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { Rewrite } from '~/cli/types'
import { isDynamicRewrite, isTypedRewrite } from '~/utils/rewrite-utils'
import type { DecoratorParams, CompileFn } from '../tpl-utils'
import { getPattern, removePropTypes } from '../tpl-utils'
import {
type CompileFn,
type DecoratorParams,
getPattern,
removePropTypes,
} from '../tpl-utils'

export const PATTERNS = {
originPath: getPattern('originPath'),
Expand Down
7 changes: 6 additions & 1 deletion src/cli/templates/decorators/with-page-viewport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { Rewrite } from '~/cli/types'
import { isDynamicRewrite, isTypedRewrite } from '~/utils/rewrite-utils'
import { getPattern, removePropTypes ,type DecoratorParams,type CompileFn } from '../tpl-utils';
import {
type CompileFn,
type DecoratorParams,
getPattern,
removePropTypes,
} from '../tpl-utils'

export const PATTERNS = {
originPath: getPattern('originPath'),
Expand Down
19 changes: 13 additions & 6 deletions src/cli/templates/decorators/with-route-segment-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { CompileFn, DecoratorParams } from '../tpl-utils'
import { getPattern, getPatternsFromNames } from '../tpl-utils'
import {
type CompileFn,
type DecoratorParams,
getPattern,
getPatternsFromNames,
} from '../tpl-utils'

const PATTERNS = getPatternsFromNames(
'dynamic',
Expand Down Expand Up @@ -37,10 +41,13 @@ const REG_EXPS: Record<ConfigVariable, RegExp> = {
}

function getCompileParams(input: string) {
return Object.entries(REG_EXPS).reduce((params, [variable, regExp]) => {
params[variable as ConfigVariable] = input.match(regExp)?.[1]
return params
}, {} as Record<ConfigVariable, string | undefined>)
return Object.entries(REG_EXPS).reduce(
(params, [variable, regExp]) => {
params[variable as ConfigVariable] = input.match(regExp)?.[1]
return params
},
{} as Record<ConfigVariable, string | undefined>
)
}

function compileConfigVariableTemplate(
Expand Down
6 changes: 3 additions & 3 deletions src/cli/templates/layout-tpl.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { getLocaleFactory } from '~/utils/locale-utils'
import { isTypedRewrite } from '~/utils/rewrite-utils'
import type { Config, Rewrite } from '../types'
import { withLayoutGenerateStaticParamsFactory } from './decorators/with-layout-generate-static-params'
import { withLayoutMetadataDecoratorFactory } from './decorators/with-layout-metadata'
import { withLayoutViewportDecoratorFactory } from './decorators/with-layout-viewport'
import { withLayoutGenerateStaticParamsFactory } from './decorators/with-layout-generate-static-params'
import { withRouteSegmentConfigFactory } from './decorators/with-route-segment-config'
import {
type CompileParams,
DecoratorParams,
removePropTypes,
compileTemplateFactory,
DecoratorParams,
getOriginNameFactory,
getOriginPathFactory,
getPatternsFromNames,
removePropTypes,
} from './tpl-utils'

export const PATTERNS = getPatternsFromNames(
Expand Down
7 changes: 5 additions & 2 deletions src/cli/templates/lib-router-schema-tpl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { RouterSchema } from '~/types'
import type { CompileParams } from './tpl-utils'
import { compileTemplateFactory, getPatternsFromNames } from './tpl-utils'
import {
type CompileParams,
compileTemplateFactory,
getPatternsFromNames,
} from './tpl-utils'

export const PATTERNS = getPatternsFromNames('schema')

Expand Down
2 changes: 1 addition & 1 deletion src/cli/templates/not-found-tpl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getLocaleFactory } from '~/utils/locale-utils'
import type { Config, Rewrite } from '../types'
import type { CompileParams } from './tpl-utils'
import {
type CompileParams,
compileTemplateFactory,
getOriginNameFactory,
getOriginPathFactory,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/templates/page-tpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { CompileError } from '../errors'
import type { Config, Rewrite } from '../types'
import { getRoute } from '../utils/getRoute'
import {
withPageGenerateStaticParamsFactory,
type PATTERNS as GENERATE_STATIC_PARAMS_PATTERS,
withPageGenerateStaticParamsFactory,
} from './decorators/with-page-generate-static-params'
import { withPageMetadataDecoratorFactory } from './decorators/with-page-metadata'
import { withPageViewportDecoratorFactory } from './decorators/with-page-viewport'
Expand Down
23 changes: 13 additions & 10 deletions src/cli/templates/tpl-utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import path from 'path'
import { getDiffPos } from '~/cli/utils/getDiffPos'
import {
alphanumeric, capitalize,
asRootPath, trimExt, trimLeadingSlash, withUnixSeparators, joinSegments
alphanumeric,
asRootPath,
capitalize,
joinSegments,
trimExt,
trimLeadingSlash,
withUnixSeparators,
} from '~/utils/path-utils'
import { pipe } from '~/utils/pipe-utils'
import type { Config, Rewrite } from '../types'
Expand Down Expand Up @@ -61,7 +66,7 @@ export function getOriginPathFactory({

const hopUps = path
.dirname(localizedRelativePath)
.split("/")
.split('/')
.slice(1)
.map(() => '..')

Expand All @@ -74,18 +79,16 @@ export function getOriginPathFactory({

export function getOriginNameFactory(suffix = 'page') {
return (rewrite: Rewrite) => {
const getSegmentName = pipe(
trimExt,
alphanumeric,
capitalize
)
const getSegmentName = pipe(trimExt, alphanumeric, capitalize)

const originPathName = rewrite.originPath.match(new RegExp(`^/${suffix}.([tj])sx?$`))
const originPathName = rewrite.originPath.match(
new RegExp(`^/${suffix}.([tj])sx?$`)
)
? `root/${suffix}`
: rewrite.originPath

// get origin path name segments split by / or - or _
return originPathName.split(/[-/_]/g).map(getSegmentName).join("")
return originPathName.split(/[-/_]/g).map(getSegmentName).join('')
}
}

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { RouterSchema } from './types'
let schema: RouterSchema

try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
schema = require('./cache/schema')
} catch {
throw new Error("Roots schema not found. Did you forget to run 'yarn roots'?")
Expand Down
1 change: 1 addition & 0 deletions src/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const schema: RouterSchema = {
}

try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const config = require(resolve(process.cwd(), 'roots.config.js'))

schema.defaultLocale = config.defaultLocale
Expand Down
Loading

0 comments on commit 39e6152

Please sign in to comment.