Skip to content

Commit

Permalink
chore: use includes replace indexOf (#48901)
Browse files Browse the repository at this point in the history
use includes replace indexOf
  • Loading branch information
li-jia-nan authored May 2, 2023
1 parent 7b2c79d commit eea3f34
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/cms-agilitycms/lib/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export async function validatePreview({ agilityPreviewKey, slug, contentID }) {
}

//sanitize incoming key (replace spaces with '+')
if (agilityPreviewKey.indexOf(` `) > -1) {
if (agilityPreviewKey.includes(` `)) {
agilityPreviewKey = agilityPreviewKey.split(` `).join(`+`)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function checkGitStatus(force) {
clean = isGitClean.sync(process.cwd())
errorMessage = 'Git directory is not clean'
} catch (err) {
if (err && err.stderr && err.stderr.indexOf('Not a git repository') >= 0) {
if (err && err.stderr && err.stderr.includes('Not a git repository')) {
clean = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ function isUserModifyWritable(style) {
// https://www.w3.org/TR/1999/WD-css3-userint-19990916#user-modify
// https://github.com/medialize/ally.js/issues/17
var userModify = style.webkitUserModify || ''
return Boolean(userModify && userModify.indexOf('write') !== -1)
return Boolean(userModify && userModify.includes('write'))
}

function hasCssOverflowScroll(style) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,9 @@ export default function HotReload({
useEffect(() => {
const handler = (event: MessageEvent<PongEvent>) => {
if (
event.data.indexOf('action') === -1 &&
!event.data.includes('action') &&
// TODO-APP: clean this up for consistency
event.data.indexOf('pong') === -1
!event.data.includes('pong')
) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const WEBPACK_BREAKING_CHANGE_POLYFILLS =
'\n\nBREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.'

function isLikelyASyntaxError(message: string) {
return stripAnsi(message).indexOf(friendlySyntaxErrorLabel) !== -1
return stripAnsi(message).includes(friendlySyntaxErrorLabel)
}

let hadMissingSassError = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function connect() {
register()

addMessageListener((event) => {
if (event.data.indexOf('action') === -1) return
if (!event.data.includes('action')) return

try {
processMessage(event)
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/client/dev/on-demand-entries-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default async (page?: string) => {
}

addMessageListener((event) => {
if (event.data.indexOf('{') === -1) return
if (!event.data.includes('{')) return
try {
const payload = JSON.parse(event.data)
// don't attempt fetching the page if we're already showing
Expand Down
6 changes: 3 additions & 3 deletions packages/next/src/client/next-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ initialize({ webpackHMR })
let buildIndicatorHandler: any = () => {}

function devPagesManifestListener(event: any) {
if (event.data.indexOf('devPagesManifest') !== -1) {
if (event.data.includes('devPagesManifest')) {
fetch(
`${assetPrefix}/_next/static/development/_devPagesManifest.json`
)
Expand All @@ -66,9 +66,9 @@ initialize({ webpackHMR })
.catch((err) => {
console.log(`Failed to fetch devPagesManifest`, err)
})
} else if (event.data.indexOf('middlewareChanges') !== -1) {
} else if (event.data.includes('middlewareChanges')) {
return window.location.reload()
} else if (event.data.indexOf('serverOnlyChanges') !== -1) {
} else if (event.data.includes('serverOnlyChanges')) {
const { pages } = JSON.parse(event.data)

// Make sure to reload when the dev-overlay is showing for an
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/shared/lib/loadable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function createLoadableComponent(loadFn: any, options: any) {
if (moduleIds) {
READY_INITIALIZERS.push((ids: any) => {
for (const moduleId of moduleIds) {
if (ids.indexOf(moduleId) !== -1) {
if (ids.includes(moduleId)) {
return init()
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/shared/lib/router/utils/format-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function formatWithValidation(url: UrlObject): string {
if (process.env.NODE_ENV === 'development') {
if (url !== null && typeof url === 'object') {
Object.keys(url).forEach((key) => {
if (urlObjectKeys.indexOf(key) === -1) {
if (!urlObjectKeys.includes(key)) {
console.warn(
`Unknown key passed via urlObject into url.format: ${key}`
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function guessEditor(): string[] {
const processNames = Object.keys(COMMON_EDITORS_MACOS)
for (let i = 0; i < processNames.length; i++) {
const processName = processNames[i]
if (output.indexOf(processName) !== -1) {
if (output.includes(processName)) {
return [(COMMON_EDITORS_MACOS as any)[processName]]
}
}
Expand All @@ -242,7 +242,7 @@ function guessEditor(): string[] {
for (let i = 0; i < runningProcesses.length; i++) {
const processPath = runningProcesses[i].trim()
const processName = path.basename(processPath)
if (COMMON_EDITORS_WIN.indexOf(processName) !== -1) {
if (COMMON_EDITORS_WIN.includes(processName)) {
return [processPath]
}
}
Expand All @@ -256,7 +256,7 @@ function guessEditor(): string[] {
const processNames = Object.keys(COMMON_EDITORS_LINUX)
for (let i = 0; i < processNames.length; i++) {
const processName = processNames[i]
if (output.indexOf(processName) !== -1) {
if (output.includes(processName)) {
return [(COMMON_EDITORS_LINUX as any)[processName] as string]
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/lib/next-webdriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default async function webdriver(

// if it's not a Next.js app return
if (
document.documentElement.innerHTML.indexOf('__NEXT_DATA__') === -1 &&
!document.documentElement.innerHTML.includes('__NEXT_DATA__') &&
// @ts-ignore next exists on window if it's a Next.js page.
typeof ((window as any).next && (window as any).next.version) ===
'undefined'
Expand Down

0 comments on commit eea3f34

Please sign in to comment.