Skip to content

Commit

Permalink
Merge branch 'canary' into script
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Jul 16, 2021
2 parents 6fa6b3a + 6645248 commit 7869c93
Show file tree
Hide file tree
Showing 31 changed files with 142 additions and 152 deletions.
5 changes: 4 additions & 1 deletion .eslintignore
Expand Up @@ -6,6 +6,10 @@ e2e-tests/**
examples/with-eslint/**
examples/with-typescript-eslint-jest/**
examples/with-kea/**
examples/with-custom-babel-config/**
examples/with-flow/**
examples/with-mobx-state-tree/**
examples/with-mobx/**
packages/next/bundles/webpack/packages/*.runtime.js
packages/next/compiled/**/*
packages/react-refresh-utils/**/*.js
Expand All @@ -18,6 +22,5 @@ packages/next-codemod/**/*.js
packages/next-codemod/**/*.d.ts
packages/next-env/**/*.d.ts
packages/create-next-app/templates/**
test/integration/async-modules/**
test/integration/eslint/**
test-timings.json
11 changes: 9 additions & 2 deletions .eslintrc.json
@@ -1,6 +1,6 @@
{
"root": true,
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"plugins": ["react", "react-hooks", "jest", "import"],
"env": {
"browser": true,
Expand All @@ -9,10 +9,17 @@
"node": true
},
"parserOptions": {
"ecmaVersion": 2018,
"requireConfigFile": false,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
},
"babelOptions": {
"presets": ["@babel/preset-env", "@babel/preset-react"],
"caller": {
// Eslint supports top level await when a parser for it is included. We enable the parser by default for Babel.
"supportsTopLevelAwait": true
}
}
},
"settings": {
Expand Down
2 changes: 1 addition & 1 deletion examples/with-flow/.eslintrc.json
@@ -1,3 +1,3 @@
{
"parser": "babel-eslint"
"extends": "next"
}
3 changes: 2 additions & 1 deletion examples/with-flow/package.json
Expand Up @@ -12,7 +12,8 @@
"react-dom": "^17.0.2"
},
"devDependencies": {
"babel-eslint": "8.2.6",
"eslint": "7.30.0",
"eslint-config-next": "latest",
"babel-plugin-transform-flow-strip-types": "6.22.0",
"flow-bin": "0.77.0"
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -40,6 +40,7 @@
},
"pre-commit": "lint-staged",
"devDependencies": {
"@babel/eslint-parser": "7.14.7",
"@babel/plugin-proposal-object-rest-spread": "7.12.1",
"@babel/preset-flow": "7.12.1",
"@babel/preset-react": "7.12.10",
Expand All @@ -62,7 +63,6 @@
"amphtml-validator": "1.0.33",
"async-sema": "3.0.1",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.3",
"babel-jest": "27.0.0-next.5",
"browserslist": "^4.14.7",
"browserstack-local": "1.4.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/eslint-config-next/index.js
Expand Up @@ -32,6 +32,10 @@ module.exports = {
allowImportExportEverywhere: true,
babelOptions: {
presets: ['next/babel'],
caller: {
// Eslint supports top level await when a parser for it is included. We enable the parser by default for Babel.
supportsTopLevelAwait: true,
},
},
},
overrides: [
Expand Down
8 changes: 5 additions & 3 deletions packages/next/cli/next-lint.ts
Expand Up @@ -28,7 +28,9 @@ const eslintOptions = (args: arg.Spec) => ({
args['--report-unused-disable-directives'] || null,
cache: args['--cache'] ?? false,
cacheLocation: args['--cache-location'] || '.eslintcache',
errorOnUnmatchedPattern: !Boolean(args['--no-error-on-unmatched-pattern']),
errorOnUnmatchedPattern: args['--error-on-unmatched-pattern']
? Boolean(args['--error-on-unmatched-pattern'])
: false,
})

const nextLint: cliCommand = (argv) => {
Expand Down Expand Up @@ -60,7 +62,7 @@ const nextLint: cliCommand = (argv) => {
'--report-unused-disable-directives': String,
'--cache': Boolean,
'--cache-location': String,
'--no-error-on-unmatched-pattern': Boolean,
'--error-on-unmatched-pattern': Boolean,

// Aliases
'-c': '--config',
Expand Down Expand Up @@ -120,7 +122,7 @@ const nextLint: cliCommand = (argv) => {
--cache-location path::String Path to the cache file or directory - default: .eslintcache
Miscellaneous:
--no-error-on-unmatched-pattern Prevent errors when pattern is unmatched - default: false
--error-on-unmatched-pattern Show errors when any file patterns are unmatched - default: false
`,
0
)
Expand Down
1 change: 1 addition & 0 deletions packages/next/lib/eslint/runLintCheck.ts
Expand Up @@ -64,6 +64,7 @@ async function lint(
let options: any = {
useEslintrc: true,
baseConfig: {},
errorOnUnmatchedPattern: false,
extensions: ['.js', '.jsx', '.ts', '.tsx'],
...eslintOptions,
}
Expand Down
16 changes: 16 additions & 0 deletions test/.eslintrc.json
@@ -0,0 +1,16 @@
{
"extends": ["next"],
"rules": {
"import/no-anonymous-default-export": "off",
"react/display-name": "off",
"@next/next/no-img-element": "off",
"jsx-a11y/alt-text": "off",
"@next/next/no-css-tags": "off",
"@next/next/no-page-custom-font": "off",
"@next/next/no-sync-scripts": "off",
"react/no-unescaped-entities": "off",
"@next/next/no-html-link-for-pages": "off",
"react/no-unknown-property": "off",
"@next/next/google-font-display": "off"
}
}
Expand Up @@ -18,6 +18,7 @@ export default () => (
<FakeA id="with-href">Will redirect as an `a` tag</FakeA>
</Link>

{/* eslint-disable-next-line @next/next/link-passhref */}
<Link href="/nav">
<FakeA id="without-href">Will not redirect as an `a` tag</FakeA>
</Link>
Expand Down
5 changes: 0 additions & 5 deletions test/integration/conformance/components/one.js

This file was deleted.

17 changes: 0 additions & 17 deletions test/integration/conformance/next.config.js

This file was deleted.

5 changes: 0 additions & 5 deletions test/integration/conformance/pages/index.js

This file was deleted.

14 changes: 0 additions & 14 deletions test/integration/conformance/pages/page1.js

This file was deleted.

24 changes: 0 additions & 24 deletions test/integration/conformance/pages/page2.js

This file was deleted.

15 changes: 0 additions & 15 deletions test/integration/conformance/pages/page3.js

This file was deleted.

43 changes: 0 additions & 43 deletions test/integration/conformance/test/index.test.js

This file was deleted.

Expand Up @@ -5,7 +5,7 @@ function AnotherPage() {
return (
<div>
<h1>Another page</h1>
<Link href="/">
<Link href="/" passHref>
<Button id="link-index">Another Button instance</Button>
</Link>
</div>
Expand Down
Expand Up @@ -6,7 +6,7 @@ function HomePage() {
return (
<div>
<h1>Home page</h1>
<Link href="/another-page">
<Link href="/another-page" passHref>
<Button id="link-other" className={styles.button}>
Another page
</Button>
Expand Down
2 changes: 2 additions & 0 deletions test/integration/document-head-warnings/pages/_document.js
@@ -1,3 +1,5 @@
/* eslint-disable @next/next/no-title-in-document-head */

import Document, { Html, Head, Main, NextScript } from 'next/document'

class MyDocument extends Document {
Expand Down
8 changes: 8 additions & 0 deletions test/integration/eslint/empty-directory/.eslintrc
@@ -0,0 +1,8 @@
{
"extends": "next",
"root": true,
"rules": {
"@next/next/no-html-link-for-pages": 0,
"@next/next/no-sync-scripts": 1
}
}
Empty file.
8 changes: 8 additions & 0 deletions test/integration/eslint/empty-directory/pages/index.js
@@ -0,0 +1,8 @@
const Home = () => (
<div>
<p>Home</p>
<script src="https://example.com" />
</div>
)

export default Home
9 changes: 9 additions & 0 deletions test/integration/eslint/eslint-ignore/.eslintrc
@@ -0,0 +1,9 @@
{
"extends": "next",
"root": true,
"rules": {
"@next/next/no-html-link-for-pages": 0,
"@next/next/no-sync-scripts": 1
},
"ignorePatterns": ["**/components/**"]
}
8 changes: 8 additions & 0 deletions test/integration/eslint/eslint-ignore/components/a.js
@@ -0,0 +1,8 @@
const A = () => (
<div>
<p>A Component</p>
/* Test */
</div>
)

export default A
8 changes: 8 additions & 0 deletions test/integration/eslint/eslint-ignore/pages/index.js
@@ -0,0 +1,8 @@
const Home = () => (
<div>
<p>Home</p>
<script src="https://example.com" />
</div>
)

export default Home
32 changes: 32 additions & 0 deletions test/integration/eslint/test/index.test.js
Expand Up @@ -13,6 +13,8 @@ const dirCustomDirectories = join(__dirname, '../custom-directories')
const dirConfigInPackageJson = join(__dirname, '../config-in-package-json')
const dirInvalidEslintVersion = join(__dirname, '../invalid-eslint-version')
const dirMaxWarnings = join(__dirname, '../max-warnings')
const dirEmptyDirectory = join(__dirname, '../empty-directory')
const dirEslintIgnore = join(__dirname, '../eslint-ignore')

describe('ESLint', () => {
describe('Next Build', () => {
Expand Down Expand Up @@ -90,6 +92,36 @@ describe('ESLint', () => {
'Your project has an older version of ESLint installed'
)
})

test('empty directories do not fail the build', async () => {
const { stdout, stderr } = await nextBuild(dirEmptyDirectory, [], {
stdout: true,
stderr: true,
})

const output = stdout + stderr
expect(output).not.toContain('Build error occurred')
expect(output).not.toContain('NoFilesFoundError')
expect(output).toContain(
'Warning: External synchronous scripts are forbidden'
)
expect(output).toContain('Compiled successfully')
})

test('eslint ignored directories do not fail the build', async () => {
const { stdout, stderr } = await nextBuild(dirEslintIgnore, [], {
stdout: true,
stderr: true,
})

const output = stdout + stderr
expect(output).not.toContain('Build error occurred')
expect(output).not.toContain('AllFilesIgnoredError')
expect(output).toContain(
'Warning: External synchronous scripts are forbidden'
)
expect(output).toContain('Compiled successfully')
})
})

describe('Next Lint', () => {
Expand Down

0 comments on commit 7869c93

Please sign in to comment.