Skip to content

Commit

Permalink
adds --quiet flag
Browse files Browse the repository at this point in the history
  • Loading branch information
housseindjirdeh committed Jun 17, 2021
1 parent b5ec567 commit 8866553
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
13 changes: 8 additions & 5 deletions packages/next/lib/eslint/runLintCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ async function lint(
lintDirs: string[],
eslintrcFile: string | null,
pkgJsonPath: string | null,
eslintOptions: any = null
eslintOptions: any = null,
reportErrorsOnly: boolean = false
): Promise<
| string
| null
Expand Down Expand Up @@ -59,7 +60,6 @@ async function lint(
'error'
)} - ESLint class not found. Please upgrade to ESLint version 7 or later`
}

let options: any = {
useEslintrc: true,
baseConfig: {},
Expand Down Expand Up @@ -110,8 +110,9 @@ async function lint(
}
const lintStart = process.hrtime()

const results = await eslint.lintFiles(lintDirs)
let results = await eslint.lintFiles(lintDirs)
if (options.fix) await ESLint.outputFixes(results)
if (reportErrorsOnly) results = await ESLint.getErrorResults(results) // Only return errors if --quiet flag is used

const formattedResult = formatResults(baseDir, results)
const lintEnd = process.hrtime(lintStart)
Expand Down Expand Up @@ -141,7 +142,8 @@ export async function runLintCheck(
baseDir: string,
lintDirs: string[],
lintDuringBuild: boolean = false,
eslintOptions: any = null
eslintOptions: any = null,
reportErrorsOnly: boolean = false
): ReturnType<typeof lint> {
try {
// Find user's .eslintrc file
Expand Down Expand Up @@ -202,7 +204,8 @@ export async function runLintCheck(
lintDirs,
eslintrcFile,
pkgJsonPath,
eslintOptions
eslintOptions,
reportErrorsOnly
)
} catch (err) {
throw err
Expand Down
2 changes: 1 addition & 1 deletion test/integration/eslint/custom-config/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"root": true,
"rules": {
"@next/next/no-html-link-for-pages": 0,
"@next/next/no-sync-scripts": 2
"@next/next/no-sync-scripts": 1
}
}
1 change: 1 addition & 0 deletions test/integration/eslint/custom-config/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Home = () => (
<div>
<p>Home</p>
<script src="https://example.com" />
/* Badly formatted comment */
</div>
)
Expand Down
23 changes: 22 additions & 1 deletion test/integration/eslint/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ describe('ESLint', () => {
})

const output = stdout + stderr
expect(output).toContain(
'Warning: External synchronous scripts are forbidden'
)
expect(output).toContain(
'Error: Comments inside children section of tag should be placed inside braces'
)
Expand Down Expand Up @@ -75,7 +78,7 @@ describe('ESLint', () => {
)
})

test.only('invalid eslint version', async () => {
test('invalid eslint version', async () => {
const { stdout, stderr } = await nextBuild(dirInvalidEslintVersion, [], {
stdout: true,
stderr: true,
Expand Down Expand Up @@ -115,6 +118,9 @@ describe('ESLint', () => {
})

const output = stdout + stderr
expect(output).toContain(
'Warning: External synchronous scripts are forbidden'
)
expect(output).toContain(
'Error: Comments inside children section of tag should be placed inside braces'
)
Expand Down Expand Up @@ -167,5 +173,20 @@ describe('ESLint', () => {
}
}
})

test('quiet flag suppresses warnings and only reports errors', async () => {
const { stdout, stderr } = await nextLint(dirCustomConfig, ['--quiet'], {
stdout: true,
stderr: true,
})

const output = stdout + stderr
expect(output).toContain(
'Error: Comments inside children section of tag should be placed inside braces'
)
expect(output).not.toContain(
'Warning: External synchronous scripts are forbidden'
)
})
})
})

0 comments on commit 8866553

Please sign in to comment.