Skip to content

Commit

Permalink
Add file extensions to options
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkldshv committed Sep 24, 2022
1 parent bf0827d commit b1b35a7
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/eslint-config-next/index.js
Expand Up @@ -107,7 +107,13 @@ module.exports = {
version: 'detect',
},
'import/parsers': {
[require.resolve('@typescript-eslint/parser')]: ['.ts', '.tsx', '.d.ts'],
[require.resolve('@typescript-eslint/parser')]: [
'.ts',
'.mts',
'.cts',
'.tsx',
'.d.ts',
],
},
'import/resolver': {
[require.resolve('eslint-import-resolver-node')]: {
Expand Down
11 changes: 10 additions & 1 deletion packages/next/cli/next-lint.ts
Expand Up @@ -18,7 +18,16 @@ import { getProjectDir } from '../lib/get-project-dir'

const eslintOptions = (args: arg.Spec, defaultCacheLocation: string) => ({
overrideConfigFile: args['--config'] || null,
extensions: args['--ext'] ?? ['.js', '.jsx', '.ts', '.tsx'],
extensions: args['--ext'] ?? [
'.js',
'.mjs',
'.cjs',
'.jsx',
'.ts',
'.mts',
'.cts',
'.tsx',
],
resolvePluginsRelativeTo: args['--resolve-plugins-relative-to'] || null,
rulePaths: args['--rulesdir'] ?? [],
fix: args['--fix'] ?? false,
Expand Down
4 changes: 4 additions & 0 deletions test/integration/eslint/mjs-cjs-linting/.eslintrc.json
@@ -0,0 +1,4 @@
{
"extends": "next",
"root": true
}
10 changes: 10 additions & 0 deletions test/integration/eslint/mjs-cjs-linting/pages/bar.mjs
@@ -0,0 +1,10 @@
export default class Bar {
render() {
return (
<div>
<h1>Hello title</h1>
<img src="img" />
</div>
)
}
}
10 changes: 10 additions & 0 deletions test/integration/eslint/mjs-cjs-linting/pages/index.cjs
@@ -0,0 +1,10 @@
export default class Home {
render() {
return (
<div>
<h1>Hello title</h1>
<script src="test"></script>
</div>
)
}
}
23 changes: 23 additions & 0 deletions test/integration/eslint/test/index.test.js
Expand Up @@ -34,6 +34,7 @@ const dirNoConfig = join(__dirname, '../no-config')
const dirEslintCache = join(__dirname, '../eslint-cache')
const dirEslintCacheCustomDir = join(__dirname, '../eslint-cache-custom-dir')
const dirFileLinting = join(__dirname, '../file-linting')
const mjsCjsLinting = join(__dirname, '../mjs-cjs-linting')

describe('ESLint', () => {
describe('Next Build', () => {
Expand Down Expand Up @@ -767,5 +768,27 @@ describe('ESLint', () => {
`Cannot write to output file path, it is a directory: ${filePath}`
)
})

test('lint files with cjs and mjs file extension', async () => {
const { stdout, stderr } = await nextLint(mjsCjsLinting, [], {
stdout: true,
stderr: true,
})

const output = stdout + stderr

expect(output).toContain('pages/bar.mjs')
expect(output).toContain(
'img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.'
)
expect(output).toContain(
'Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element'
)

expect(output).toContain('pages/index.cjs')
expect(output).toContain(
'Synchronous scripts should not be used. See: https://nextjs.org/docs/messages/no-sync-scripts'
)
})
})
})

0 comments on commit b1b35a7

Please sign in to comment.