Skip to content

Commit

Permalink
chore(lint): enable 'typescript-eslint/prefer-string-starts-ends-with' (
Browse files Browse the repository at this point in the history
#11280)

Enables the `typescript-eslint/prefer-string-starts-ends-with` rule and
fixes issues that resulted.
  • Loading branch information
Josh-Walker-GM authored Aug 16, 2024
1 parent 5ea976d commit bbf16c1
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 11 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ module.exports = {
camelcase: 'off',

// TODO(jgmw): Work through these and either keep disabled or fix and re-enable
'@typescript-eslint/prefer-string-starts-ends-with': 'off',
'@typescript-eslint/await-thenable': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
Expand Down
4 changes: 2 additions & 2 deletions packages/adapters/fastify/web/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** Ensures that `path` starts and ends with a slash ('/') */
export function coerceRootPath(path: string) {
const prefix = path.charAt(0) !== '/' ? '/' : ''
const suffix = path.charAt(path.length - 1) !== '/' ? '/' : ''
const prefix = !path.startsWith('/') ? '/' : ''
const suffix = !path.endsWith('/') ? '/' : ''

return `${prefix}${path}${suffix}`
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function (
if (process.platform === 'win32') {
newImport = newImport.replaceAll('\\', '/')
}
if (newImport.indexOf('.') !== 0) {
if (!newImport.startsWith('.')) {
newImport = './' + newImport
}
const newSource = t.stringLiteral(newImport)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const handler = async ({ force }: Args) => {
.split('\n')

const handlerIndex = contentLines.findLastIndex((line) =>
/^export const handler = createGraphQLHandler\({/.test(line),
line.startsWith('export const handler = createGraphQLHandler({'),
)

const pluginsIndex = contentLines.findLastIndex((line) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/src/coercion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,6 @@ export const setCoercion = (
valueAs, // type
emptyAs, // emptyAs
validation.required !== undefined && validation.required !== false, // required
/Id$/.test(name || ''), // isId
(name || '').endsWith('Id'), // isId
)
}
2 changes: 1 addition & 1 deletion packages/router/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const LocationAwareRouter: React.FC<RouterProps> = ({
let redirectPath: string | undefined = undefined

if (redirect) {
if (redirect[0] === '/') {
if (redirect.startsWith('/')) {
redirectPath = replaceParams(redirect, allParams)
} else {
const redirectRouteObject = Object.values(pathRouteMap).find(
Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/rsc/ServerRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const Router: React.FC<RouterProps> = ({ paramTypes, children }) => {
let redirectPath: string | undefined = undefined

if (redirect) {
if (redirect[0] === '/') {
if (redirect.startsWith('/')) {
redirectPath = replaceParams(redirect, allParams)
} else {
const redirectRouteObject = Object.values(pathRouteMap).find(
Expand Down
4 changes: 2 additions & 2 deletions packages/router/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function paramsForRoute(route: string) {

// Normalize the name
let name = parts[0]
if (name.slice(-3) === '...') {
if (name.endsWith('...')) {
// Globs have their ellipsis removed
name = name.slice(0, -3)
}
Expand All @@ -47,7 +47,7 @@ export function paramsForRoute(route: string) {
let type = parts[1]
if (!type) {
// Strings and Globs are implicit in the syntax
type = match.slice(-3) === '...' ? 'Glob' : 'String'
type = match.endsWith('...') ? 'Glob' : 'String'
}

return [name, type, `{${match}}`]
Expand Down
2 changes: 1 addition & 1 deletion packages/structure/src/x/URL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function fileUriToPath(uri: string, sep = path_sep): string {
if (
typeof uri !== 'string' ||
uri.length <= 7 ||
uri.substring(0, 7) !== FILE_SCHEME
!uri.startsWith(FILE_SCHEME)
) {
throw new TypeError('must pass in a file:// URI to convert to a file path')
}
Expand Down

0 comments on commit bbf16c1

Please sign in to comment.