Skip to content

Commit

Permalink
refactor(nx-python): fix sonarcloud code smell
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasvieirasilva committed Nov 10, 2023
1 parent df53e89 commit 5c03227
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions packages/nx-python/src/generators/poetry-project/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,10 @@ function normalizeOptions(
tree: Tree,
options: PoetryProjectGeneratorSchema
): NormalizedSchema {
let projectName = options.name;
let projectRoot = options.directory || options.name;
if (options.projectNameAndRootFormat === 'derived') {
const name = names(options.name).fileName;
const projectDirectory = options.directory
? `${names(options.directory).fileName}/${name}`
: name;
projectName = projectDirectory.replace(/\//g, '-');
projectRoot = `${
options.projectType === 'application'
? getWorkspaceLayout(tree).appsDir
: getWorkspaceLayout(tree).libsDir
}/${projectDirectory}`;
}
const { projectName, projectRoot } = calculateProjectNameAndRoot(
options,
tree
);

const parsedTags = options.tags
? options.tags.split(',').map((s) => s.trim())
Expand Down Expand Up @@ -118,6 +108,29 @@ function normalizeOptions(
};
}

function calculateProjectNameAndRoot(
options: PoetryProjectGeneratorSchema,
tree: Tree
) {
let projectName = options.name;
let projectRoot = options.directory || options.name;

if (options.projectNameAndRootFormat === 'derived') {
const name = names(options.name).fileName;
const projectDirectory = options.directory
? `${names(options.directory).fileName}/${name}`
: name;
projectName = projectDirectory.replace(/\//g, '-');
projectRoot = `${
options.projectType === 'application'
? getWorkspaceLayout(tree).appsDir
: getWorkspaceLayout(tree).libsDir
}/${projectDirectory}`;
}

return { projectName, projectRoot };
}

function getPyTestAddopts(
options: PoetryProjectGeneratorSchema,
projectRoot: string
Expand Down

0 comments on commit 5c03227

Please sign in to comment.