fix(core): handle string and array parserOptions.project values (#17500)
This commit is contained in:
parent
a21ab98ca8
commit
f18d50ca0c
@ -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}` });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -64,14 +64,20 @@ export function updateEslintrcJson(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
eslintRcJson.overrides?.forEach((o) => {
|
eslintRcJson.overrides?.forEach(
|
||||||
if (o.parserOptions?.project) {
|
(o: { parserOptions?: { project?: string | string[] } }) => {
|
||||||
o.parserOptions.project = o.parserOptions.project.map((p) =>
|
if (o.parserOptions?.project) {
|
||||||
p.replace(project.root, schema.relativeToRootDestination)
|
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;
|
return eslintRcJson;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user