-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-eslint): add eslintConfigFromNxProject helper that doesn'…
…t include nx project deps Signed-off-by: Vojtech Masek <vojtech@flowup.cz>
- Loading branch information
Showing
5 changed files
with
76 additions
and
3 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
39 changes: 39 additions & 0 deletions
39
packages/plugin-eslint/src/lib/nx/find-project-without-deps.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,39 @@ | ||
import type { ESLintTarget } from '../config'; | ||
import { nxProjectsToConfig } from './projects-to-config'; | ||
|
||
/** | ||
* Accepts a target Nx projects, converts lint configurations to Code PushUp ESLint plugin parameters. | ||
* | ||
* Use when you wish to include a targeted subset of your Nx monorepo in your Code PushUp project. | ||
* If you prefer to include all Nx projects, refer to {@link eslintConfigFromAllNxProjects} instead, | ||
* if you'd like to auto include all dependencies of the provided target project use {@link eslintConfigFromNxProjectAndDeps} instead. | ||
* | ||
* @example | ||
* import eslintPlugin, { | ||
* eslintConfigFromNxProject, | ||
* } from '@code-pushup/eslint-plugin'; | ||
* | ||
* const projectName = 'backoffice'; // <-- name from project.json | ||
* | ||
* export default { | ||
* plugins: [ | ||
* await eslintPlugin( | ||
* await eslintConfigFromNxProject(projectName) | ||
* ) | ||
* ] | ||
* } | ||
* | ||
* @param projectName Nx project serving as main entry point | ||
* @returns ESLint config and patterns, intended to be passed to {@link eslintPlugin} | ||
*/ | ||
export async function eslintConfigFromNxProject( | ||
projectName: string, | ||
): Promise<ESLintTarget[]> { | ||
const { createProjectGraphAsync } = await import('@nx/devkit'); | ||
const projectGraph = await createProjectGraphAsync({ exitOnError: false }); | ||
|
||
return nxProjectsToConfig( | ||
projectGraph, | ||
project => !!project.name && project.name === projectName, | ||
); | ||
} |
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