-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nextjs): remove temporary patch for next eslint rules (#20863)
- Loading branch information
Showing
8 changed files
with
185 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
packages/next/src/migrations/update-17-2-7/remove-eslint-rules-patch.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import { Tree, addProjectConfiguration, writeJson } from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports'; | ||
|
||
import update from './remove-eslint-rules-patch'; | ||
import { readJson } from '@nx/devkit'; | ||
|
||
describe('update-nx-next-dependency', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it('should remove @next/next/no-html-link-for-pages in json configs', async () => { | ||
tree.write('.eslintrc.json', '{}'); | ||
|
||
addProjectConfiguration(tree, 'my-pkg', { | ||
root: 'packages/my-pkg', | ||
}); | ||
writeJson(tree, `packages/my-pkg/.eslintrc.json`, { | ||
root: true, | ||
ignorePatterns: ['!**/*'], | ||
plugins: ['@nx'], | ||
overrides: [ | ||
{ | ||
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], | ||
rules: { | ||
'@next/next/no-html-link-for-pages': ['error', 'apps/lint/pages'], | ||
'no-console': 'error', | ||
}, | ||
}, | ||
{ | ||
files: ['**/*.*'], | ||
rules: { '@next/next/no-html-link-for-pages': 'off' }, | ||
}, | ||
{ | ||
files: ['**/*.ts', '**/*.tsx'], | ||
rules: {}, | ||
}, | ||
{ | ||
files: ['**/*.js', '**/*.jsx'], | ||
rules: {}, | ||
}, | ||
], | ||
}); | ||
|
||
await update(tree); | ||
|
||
expect(readJson(tree, `packages/my-pkg/.eslintrc.json`).overrides) | ||
.toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"files": [ | ||
"**/*.ts", | ||
"**/*.tsx", | ||
"**/*.js", | ||
"**/*.jsx", | ||
], | ||
"rules": { | ||
"@next/next/no-html-link-for-pages": [ | ||
"error", | ||
"apps/lint/pages", | ||
], | ||
"no-console": "error", | ||
}, | ||
}, | ||
{ | ||
"files": [ | ||
"**/*.ts", | ||
"**/*.tsx", | ||
], | ||
"rules": {}, | ||
}, | ||
{ | ||
"files": [ | ||
"**/*.js", | ||
"**/*.jsx", | ||
], | ||
"rules": {}, | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
it('should remove @next/next/no-html-link-for-pages in flat configs', async () => { | ||
tree.write('eslint.config.js', 'module.exports = []'); | ||
|
||
addProjectConfiguration(tree, 'my-pkg', { | ||
root: 'packages/my-pkg', | ||
}); | ||
tree.write( | ||
`packages/my-pkg/eslint.config.js`, | ||
`const { FlatCompat } = require('@eslint/eslintrc'); | ||
const baseConfig = require('../../eslint.config.js'); | ||
const js = require('@eslint/js'); | ||
const compat = new FlatCompat({ | ||
baseDirectory: __dirname, | ||
recommendedConfig: js.configs.recommended, | ||
}); | ||
module.exports = [ | ||
...baseConfig, | ||
...compat.extends( | ||
'plugin:@nx/react-typescript', | ||
'next', | ||
'next/core-web-vitals' | ||
), | ||
{ | ||
files: ['**/*.*'], | ||
rules: { '@next/next/no-html-link-for-pages': 'off' }, | ||
}, | ||
{ | ||
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], | ||
rules: { | ||
'@next/next/no-html-link-for-pages': ['error', 'apps/lint/pages'], | ||
'no-console': 'error', | ||
}, | ||
}, | ||
{ | ||
files: ['**/*.ts', '**/*.tsx'], | ||
rules: {}, | ||
}, | ||
{ | ||
files: ['**/*.js', '**/*.jsx'], | ||
rules: {}, | ||
}, | ||
...compat.config({ env: { jest: true } }).map((config) => ({ | ||
...config, | ||
files: ['**/*.spec.ts', '**/*.spec.tsx', '**/*.spec.js', '**/*.spec.jsx'], | ||
})), | ||
{ ignores: ['.next/**/*'] }, | ||
];` | ||
); | ||
|
||
await update(tree); | ||
|
||
expect( | ||
tree.read(`packages/my-pkg/eslint.config.js`, 'utf-8') | ||
).not.toContain("'@next/next/no-html-link-for-pages': 'off'"); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/next/src/migrations/update-17-2-7/remove-eslint-rules-patch.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Tree, formatFiles, getProjects } from '@nx/devkit'; | ||
import { updateOverrideInLintConfig } from '@nx/eslint/src/generators/utils/eslint-file'; | ||
|
||
export default async function update(tree: Tree) { | ||
const projects = getProjects(tree); | ||
projects.forEach((project) => { | ||
updateOverrideInLintConfig( | ||
tree, | ||
project.root, | ||
(o) => | ||
o.rules?.['@next/next/no-html-link-for-pages'] && | ||
o.files?.includes('**/*.*'), | ||
(o) => undefined | ||
); | ||
}); | ||
|
||
await formatFiles(tree); | ||
} |