Skip to content

Commit

Permalink
build: fix some sonar linting
Browse files Browse the repository at this point in the history
  • Loading branch information
khalilou88 committed Feb 29, 2024
1 parent c9e1b74 commit 6022bb8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
22 changes: 10 additions & 12 deletions packages/nx-gradle/src/generators/init/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function updateNxJson(tree: Tree, options: NormalizedSchema) {

function updateGitIgnore(tree: Tree, options: NormalizedSchema) {
const filePath = '.gitignore';
const contents = tree.read(filePath, 'utf-8') || '';
const contents = tree.read(filePath, 'utf-8') ?? '';

const gradleIgnores = [
'\n',
Expand Down Expand Up @@ -214,16 +214,14 @@ function addOrUpdatePrettierRc(tree: Tree) {
// return modified JSON object
return prettierRcJson;
});
} else if (prettierrcNameOptions.every((name) => !tree.exists(name))) {
writeJson(tree, prettierRcPath, {
plugins: ['prettier-plugin-java'],
});
} else {
if (prettierrcNameOptions.every((name) => !tree.exists(name))) {
writeJson(tree, prettierRcPath, {
plugins: ['prettier-plugin-java'],
});
} else {
logger.warn(
'Please add prettier-plugin-java plugin to your prettier config file',
);
}
logger.warn(
'Please add prettier-plugin-java plugin to your prettier config file',
);
}
}

Expand All @@ -232,7 +230,7 @@ function addOrUpdatePrettierIgnore(tree: Tree) {
const gradlePrettierIgnores = ['# Gradle build', '\nbuild/'];
if (tree.exists(prettierIgnorePath)) {
const prettierIgnoreOldContent =
tree.read(prettierIgnorePath, 'utf-8') || '';
tree.read(prettierIgnorePath, 'utf-8') ?? '';

gradlePrettierIgnores.unshift('\n\n');
const prettierIgnoreContent = prettierIgnoreOldContent.concat(
Expand All @@ -257,7 +255,7 @@ function addOrUpdateGitattributes(tree: Tree) {
];

if (tree.exists(gitattributesPath)) {
const gitattributesOldContent = tree.read(gitattributesPath, 'utf-8') || '';
const gitattributesOldContent = tree.read(gitattributesPath, 'utf-8') ?? '';
attributes.unshift('\n\n');

const gitattributesContent = gitattributesOldContent.concat(
Expand Down
24 changes: 11 additions & 13 deletions packages/nx-maven/src/generators/init/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function updateNxJson(tree: Tree, options: NormalizedSchema) {

function updateGitIgnore(tree: Tree, options: NormalizedSchema) {
const filePath = '.gitignore';
const contents = tree.read(filePath, 'utf-8') || '';
const contents = tree.read(filePath, 'utf-8') ?? '';

const mavenIgnores = [
'\n',
Expand Down Expand Up @@ -227,17 +227,15 @@ function addOrUpdatePrettierRc(tree: Tree) {
// return modified JSON object
return prettierRcJson;
});
} else if (prettierrcNameOptions.every((name) => !tree.exists(name))) {
writeJson(tree, prettierRcPath, {
xmlWhitespaceSensitivity: 'ignore',
plugins: ['@prettier/plugin-xml', 'prettier-plugin-java'],
});
} else {
if (prettierrcNameOptions.every((name) => !tree.exists(name))) {
writeJson(tree, prettierRcPath, {
xmlWhitespaceSensitivity: 'ignore',
plugins: ['@prettier/plugin-xml', 'prettier-plugin-java'],
});
} else {
logger.warn(
'Please add xmlWhitespaceSensitivity with ignore value, @prettier/plugin-xml and prettier-plugin-java plugins to your prettier config file',
);
}
logger.warn(
'Please add xmlWhitespaceSensitivity with ignore value, @prettier/plugin-xml and prettier-plugin-java plugins to your prettier config file',
);
}
}

Expand All @@ -257,7 +255,7 @@ function addOrUpdatePrettierIgnore(tree: Tree, options: NormalizedSchema) {

if (tree.exists(prettierIgnorePath)) {
const prettierIgnoreOldContent =
tree.read(prettierIgnorePath, 'utf-8') || '';
tree.read(prettierIgnorePath, 'utf-8') ?? '';
mavenPrettierIgnores.unshift('\n\n');

const prettierIgnoreContent = prettierIgnoreOldContent.concat(
Expand All @@ -282,7 +280,7 @@ function addOrUpdateGitattributes(tree: Tree) {
];

if (tree.exists(gitattributesPath)) {
const gitattributesOldContent = tree.read(gitattributesPath, 'utf-8') || '';
const gitattributesOldContent = tree.read(gitattributesPath, 'utf-8') ?? '';
attributes.unshift('\n\n');

const gitattributesContent = gitattributesOldContent.concat(
Expand Down

0 comments on commit 6022bb8

Please sign in to comment.