Skip to content

Commit

Permalink
fix(core): handle string and array parserOptions.project values (#17500)
Browse files Browse the repository at this point in the history
  • Loading branch information
barbados-clemens authored Jun 14, 2023
1 parent a21ab98 commit f18d50c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,33 @@ describe('updateEslint', () => {
})
);
});

it('should update .eslintrc.json parserOptions.project as a string', async () => {
await libraryGenerator(tree, {
name: 'my-lib',
linter: Linter.EsLint,
setParserOptionsProject: true,
});

// Add another parser project to eslint.json
const storybookProject = '.storybook/tsconfig.json';
updateJson(tree, '/libs/my-lib/.eslintrc.json', (eslintRcJson) => {
eslintRcJson.overrides[0].parserOptions.project = `libs/my-lib/${storybookProject}`;
return eslintRcJson;
});

// This step is usually handled elsewhere
tree.rename(
'libs/my-lib/.eslintrc.json',
'libs/shared/my-destination/.eslintrc.json'
);
const projectConfig = readProjectConfiguration(tree, 'my-lib');

updateEslintrcJson(tree, schema, projectConfig);

expect(
readJson(tree, '/libs/shared/my-destination/.eslintrc.json').overrides[0]
.parserOptions
).toEqual({ project: `libs/shared/my-destination/${storybookProject}` });
});
});
20 changes: 13 additions & 7 deletions packages/workspace/src/generators/move/lib/update-eslintrc-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,20 @@ export function updateEslintrcJson(
);
}

eslintRcJson.overrides?.forEach((o) => {
if (o.parserOptions?.project) {
o.parserOptions.project = o.parserOptions.project.map((p) =>
p.replace(project.root, schema.relativeToRootDestination)
);
eslintRcJson.overrides?.forEach(
(o: { parserOptions?: { project?: string | string[] } }) => {
if (o.parserOptions?.project) {
o.parserOptions.project = Array.isArray(o.parserOptions.project)
? o.parserOptions.project.map((p) =>
p.replace(project.root, schema.relativeToRootDestination)
)
: o.parserOptions.project.replace(
project.root,
schema.relativeToRootDestination
);
}
}
});

);
return eslintRcJson;
});
}

1 comment on commit f18d50c

@vercel
Copy link

@vercel vercel bot commented on f18d50c Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev
nx-five.vercel.app

Please sign in to comment.