Skip to content

Commit

Permalink
feat(core): support prettier v3 as a formatter
Browse files Browse the repository at this point in the history
closed #17990
  • Loading branch information
Michsior14 committed Aug 15, 2023
1 parent 40d66ec commit bcb4930
Show file tree
Hide file tree
Showing 27 changed files with 1,891 additions and 6 deletions.
8 changes: 8 additions & 0 deletions docs/generated/manifests/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -6384,6 +6384,14 @@
"children": [],
"isExternal": false,
"disableCollapsible": false
},
{
"id": "convert-to-flat-config",
"path": "/packages/linter/generators/convert-to-flat-config",
"name": "convert-to-flat-config",
"children": [],
"isExternal": false,
"disableCollapsible": false
}
],
"isExternal": false,
Expand Down
9 changes: 9 additions & 0 deletions docs/generated/manifests/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,15 @@
"originalFilePath": "/packages/linter/src/generators/workspace-rule/schema.json",
"path": "/packages/linter/generators/workspace-rule",
"type": "generator"
},
"/packages/linter/generators/convert-to-flat-config": {
"description": "Convert an Nx workspace to a Flat ESLint config.",
"file": "generated/packages/linter/generators/convert-to-flat-config.json",
"hidden": false,
"name": "convert-to-flat-config",
"originalFilePath": "/packages/linter/src/generators/convert-to-flat-config/schema.json",
"path": "/packages/linter/generators/convert-to-flat-config",
"type": "generator"
}
},
"path": "/packages/linter"
Expand Down
9 changes: 9 additions & 0 deletions docs/generated/packages-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,15 @@
"originalFilePath": "/packages/linter/src/generators/workspace-rule/schema.json",
"path": "linter/generators/workspace-rule",
"type": "generator"
},
{
"description": "Convert an Nx workspace to a Flat ESLint config.",
"file": "generated/packages/linter/generators/convert-to-flat-config.json",
"hidden": false,
"name": "convert-to-flat-config",
"originalFilePath": "/packages/linter/src/generators/convert-to-flat-config/schema.json",
"path": "linter/generators/convert-to-flat-config",
"type": "generator"
}
],
"githubRoot": "https://github.com/nrwl/nx/blob/master",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "convert-to-flat-config",
"factory": "./src/generators/convert-to-flat-config/generator",
"schema": {
"$schema": "http://json-schema.org/schema",
"$id": "ConvertToFlatConfig",
"cli": "nx",
"description": "Convert an Nx workspace to a Flat ESLint config.",
"type": "object",
"properties": {
"skipFormat": {
"type": "boolean",
"description": "Skip formatting files.",
"default": false,
"x-priority": "internal"
}
},
"additionalProperties": false,
"required": [],
"presets": []
},
"description": "Convert an Nx workspace to a Flat ESLint config.",
"implementation": "/packages/linter/src/generators/convert-to-flat-config/generator.ts",
"aliases": [],
"hidden": false,
"path": "/packages/linter/src/generators/convert-to-flat-config/schema.json",
"type": "generator"
}
1 change: 1 addition & 0 deletions docs/shared/reference/sitemap.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@
- [generators](/packages/linter/generators)
- [workspace-rules-project](/packages/linter/generators/workspace-rules-project)
- [workspace-rule](/packages/linter/generators/workspace-rule)
- [convert-to-flat-config](/packages/linter/generators/convert-to-flat-config)
- [nest](/packages/nest)
- [documents](/packages/nest/documents)
- [Overview](/packages/nest/documents/overview)
Expand Down
75 changes: 75 additions & 0 deletions e2e/linter/src/linter.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import * as path from 'path';
import {
checkFilesDoNotExist,
checkFilesExist,
cleanupProject,
createFile,
getSelectedPackageManager,
newProject,
readFile,
readJson,
runCLI,
runCreateWorkspace,
uniq,
updateFile,
updateJson,
Expand Down Expand Up @@ -537,6 +540,78 @@ describe('Linter', () => {
});
});

describe('Flat config', () => {
const packageManager = getSelectedPackageManager() || 'pnpm';

afterEach(() => cleanupProject());

it('should convert integrated to flat config', () => {
const myapp = uniq('myapp');
const mylib = uniq('mylib');

runCreateWorkspace(myapp, {
preset: 'react-monorepo',
appName: myapp,
style: 'css',
packageManager,
bundler: 'vite',
e2eTestRunner: 'none',
});
runCLI(`generate @nx/js:lib ${mylib}`);

// migrate to flat structure
runCLI(`generate @nx/linter:convert-to-flat-config`);
checkFilesExist(
'eslint.config.js',
`apps/${myapp}/eslint.config.js`,
`libs/${mylib}/eslint.config.js`
);
checkFilesDoNotExist(
'.eslintrc.json',
`apps/${myapp}/.eslintrc.json`,
`libs/${mylib}/.eslintrc.json`
);

const outFlat = runCLI(`affected -t lint`, {
silenceError: true,
});
expect(outFlat).toContain('All files pass linting');
}, 1000000);

it('should convert standalone to flat config', () => {
const myapp = uniq('myapp');
const mylib = uniq('mylib');

runCreateWorkspace(myapp, {
preset: 'react-standalone',
appName: myapp,
style: 'css',
packageManager,
bundler: 'vite',
e2eTestRunner: 'none',
});
runCLI(`generate @nx/js:lib ${mylib}`);

// migrate to flat structure
runCLI(`generate @nx/linter:convert-to-flat-config`);
checkFilesExist(
'eslint.config.js',
`${mylib}/eslint.config.js`,
'eslint.base.config.js'
);
checkFilesDoNotExist(
'.eslintrc.json',
`${mylib}/.eslintrc.json`,
'.eslintrc.base.json'
);

const outFlat = runCLI(`affected -t lint`, {
silenceError: true,
});
expect(outFlat).toContain('All files pass linting');
}, 1000000);
});

describe('Root projects migration', () => {
beforeEach(() => newProject());
afterEach(() => cleanupProject());
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@babel/runtime": "^7.22.6",
"@eslint/eslintrc": "^2.1.1",
"@eslint/js": "^8.46.0",
"@floating-ui/react": "0.19.2",
"@jest/reporters": "^29.4.1",
"@jest/test-result": "^29.4.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ exports[`workspace move to nx layout should create nx.json 1`] = `
"!{projectRoot}/**/*.spec.[jt]s",
"!{projectRoot}/karma.conf.js",
"!{projectRoot}/.eslintrc.json",
"!{projectRoot}/eslint.config.js",
],
"sharedGlobals": [],
},
Expand All @@ -118,6 +119,7 @@ exports[`workspace move to nx layout should create nx.json 1`] = `
"inputs": [
"default",
"{workspaceRoot}/.eslintrc.json",
"{workspaceRoot}/eslint.config.js",
],
},
"test": {
Expand Down
10 changes: 8 additions & 2 deletions packages/angular/src/generators/ng-add/utilities/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ export function createNxJson(
'!{projectRoot}/karma.conf.js',
]
: []),
targets.lint ? '!{projectRoot}/.eslintrc.json' : undefined,
...(targets.lint
? ['!{projectRoot}/.eslintrc.json', '!{projectRoot}/eslint.config.js']
: []),
].filter(Boolean),
},
targetDefaults: {
Expand All @@ -91,7 +93,11 @@ export function createNxJson(
: undefined,
lint: targets.lint
? {
inputs: ['default', '{workspaceRoot}/.eslintrc.json'],
inputs: [
'default',
'{workspaceRoot}/.eslintrc.json',
'{workspaceRoot}/eslint.config.js',
],
}
: undefined,
e2e: targets.e2e
Expand Down
5 changes: 5 additions & 0 deletions packages/linter/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"factory": "./src/generators/workspace-rule/workspace-rule#lintWorkspaceRuleGenerator",
"schema": "./src/generators/workspace-rule/schema.json",
"description": "Create a new Workspace ESLint rule."
},
"convert-to-flat-config": {
"factory": "./src/generators/convert-to-flat-config/generator",
"schema": "./src/generators/convert-to-flat-config/schema.json",
"description": "Convert an Nx workspace to a Flat ESLint config."
}
}
}
3 changes: 2 additions & 1 deletion packages/linter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"tmp": "~0.2.1",
"tslib": "^2.3.0",
"@nx/devkit": "file:../devkit",
"@nx/js": "file:../js"
"@nx/js": "file:../js",
"typescript": "~5.1.3"
},
"peerDependenciesMeta": {
"eslint": {
Expand Down
5 changes: 4 additions & 1 deletion packages/linter/src/executors/eslint/lint.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ Please see https://nx.dev/guides/eslint for full guidance on how to resolve this
.filter((pattern) => !!pattern)
.map((pattern) => `- '${pattern}'`);
if (ignoredPatterns.length) {
const ignoreSection = useFlatConfig
? `'ignores' configuration`
: `'.eslintignore' file`;
throw new Error(
`All files matching the following patterns are ignored:\n${ignoredPatterns.join(
'\n'
)}\n\nPlease check your '.eslintignore' file.`
)}\n\nPlease check your ${ignoreSection}.`
);
}
throw new Error(
Expand Down
Loading

0 comments on commit bcb4930

Please sign in to comment.