Skip to content

Commit

Permalink
feat(generators): remove linters (#510)
Browse files Browse the repository at this point in the history
* feat(generators): remove linters

* build: work in progress

* build: work in progress

* build: work in progress

* build: work in progress

* build: work in progress

* build: work in progress

* build: work in progress

* build: work in progress

* build: work in progress

* build: work in progress

---------

Co-authored-by: khalilou88 <[email protected]>
  • Loading branch information
khalilou88 and khalilou88 authored Oct 12, 2023
1 parent 5b8f985 commit 877814a
Show file tree
Hide file tree
Showing 47 changed files with 406 additions and 1,136 deletions.
1 change: 0 additions & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
],
"dependencies": {
"@nx/devkit": "16.10.0",
"axios": "^1.5.1",
"nx": "16.10.0",
"tslib": "^2.6.2"
}
Expand Down
7 changes: 3 additions & 4 deletions packages/common/src/executors/ktformat/executor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { ExecutorContext, logger } from '@nx/devkit';
import { getProjectSourceRoot, runCommand } from '../../.';
import { KotlinFormatExecutorSchema } from './schema';

export default async function runExecutor(
Expand All @@ -8,7 +8,6 @@ export default async function runExecutor(
ktlintPath: string,
) {
logger.info(`Executor ran for Kotlin Format: ${JSON.stringify(options)}`);
const projectSourceRoot = getProjectSourceRoot(context);
const command = `java --add-opens java.base/java.lang=ALL-UNNAMED -jar ${ktlintPath} -F "${projectSourceRoot}/**/*.kt"`;
return runCommand(command);
logger.warn('This Executor do nothing');
return { success: true };
}
13 changes: 0 additions & 13 deletions packages/common/src/executors/lint/checkstyle-lint.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/common/src/executors/lint/ktlint.ts

This file was deleted.

12 changes: 0 additions & 12 deletions packages/common/src/executors/lint/pmd-lint.ts

This file was deleted.

11 changes: 1 addition & 10 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@ export * from './executors/ktformat/schema';
import runKtFormatExecutor from './executors/ktformat/executor';

export * from './executors/lint/schema';
import runCheckstyleLintExecutor from './executors/lint/checkstyle-lint';
import runKtlintExecutor from './executors/lint/ktlint';
import runPmdLintExecutor from './executors/lint/pmd-lint';

import runQuarkusBuildImageExecutor from './executors/build-image/quarkus/executor';

export {
runKtFormatExecutor,
runCheckstyleLintExecutor,
runKtlintExecutor,
runPmdLintExecutor,
runQuarkusBuildImageExecutor,
};
export { runKtFormatExecutor, runQuarkusBuildImageExecutor };
147 changes: 2 additions & 145 deletions packages/common/src/lib/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { ExecutorContext, workspaceRoot } from '@nx/devkit';
import axios from 'axios';
import * as fs from 'fs';
import * as path from 'path';
import * as stream from 'stream';
import { promisify } from 'util';
import { GetVersionFunction } from '../types';
import { readNxJson, workspaceLayout } from 'nx/src/config/configuration';
import { execSync } from 'child_process';
import { ExecutorContext } from '@nx/devkit';
import { workspaceLayout } from 'nx/src/config/configuration';

export function getProject(context: ExecutorContext) {
if (!context.projectName) {
Expand Down Expand Up @@ -48,142 +41,6 @@ export function normalizeName(name: string) {
return name.replace(/[^0-9a-zA-Z]/g, '-');
}

const finished = promisify(stream.finished);
export async function downloadFile(
fileUrl: string,
outputLocationPath: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): Promise<any> {
const writer = fs.createWriteStream(outputLocationPath);
return axios({
method: 'get',
url: fileUrl,
responseType: 'stream',
}).then((response) => {
response.data.pipe(writer);
return finished(writer); //this is a Promise
});
}

export async function getKtlintPath(
getKtlintVersion: GetVersionFunction,
dir = workspaceRoot,
) {
const version = getKtlintVersion(dir);

const downloadUrl = `https://github.com/pinterest/ktlint/releases/download/${version}/ktlint`;

let outputDirectory;
const nxJson = readNxJson();
if (nxJson.installation) {
outputDirectory = path.join(
dir,
'.nx',
'installation',
'node_modules',
'@jnxplus',
'tools',
'linters',
'ktlint',
);
} else {
outputDirectory = path.join(
dir,
'node_modules',
'@jnxplus',
'tools',
'linters',
'ktlint',
);
}

if (!fs.existsSync(outputDirectory)) {
fs.mkdirSync(outputDirectory, { recursive: true });
}

const ktlintAbsolutePath = path.join(outputDirectory, 'ktlint');
if (!fs.existsSync(ktlintAbsolutePath)) {
await downloadFile(downloadUrl, ktlintAbsolutePath);
} else if (isAnotherVersion(ktlintAbsolutePath, version)) {
fs.unlinkSync(ktlintAbsolutePath);
await downloadFile(downloadUrl, ktlintAbsolutePath);
}
return ktlintAbsolutePath;
}

function isAnotherVersion(ktlintAbsolutePath: string, version: string) {
const jarVersion = execSync(`java -jar ${ktlintAbsolutePath} --version`)
.toString()
.trim();
return jarVersion !== version;
}

export async function getCheckstylePath(
getCheckstyleVersion: GetVersionFunction,
dir = workspaceRoot,
) {
const version = getCheckstyleVersion(dir);

const checkstyleJarName = `checkstyle-${version}-all.jar`;
const downloadUrl = `https://github.com/checkstyle/checkstyle/releases/download/checkstyle-${version}/${checkstyleJarName}`;

let outputDirectory;
const nxJson = readNxJson();
if (nxJson.installation) {
outputDirectory = path.join(
dir,
'.nx',
'installation',
'node_modules',
'@jnxplus',
'tools',
'linters',
'checkstyle',
);
} else {
outputDirectory = path.join(
dir,
'node_modules',
'@jnxplus',
'tools',
'linters',
'checkstyle',
);
}

if (!fs.existsSync(outputDirectory)) {
fs.mkdirSync(outputDirectory, { recursive: true });
}

const checkstyleJarAbsolutePath = path.join(
outputDirectory,
checkstyleJarName,
);

if (!fs.existsSync(checkstyleJarAbsolutePath)) {
await downloadFile(downloadUrl, checkstyleJarAbsolutePath);
}
return checkstyleJarAbsolutePath;
}

export function isE2eTest(tmpWorkspaceRoot: string) {
return (
fs.existsSync(tmpWorkspaceRoot) && isSubdir(tmpWorkspaceRoot, process.cwd())
);
}

function isSubdir(parentPath: string, childPath: string) {
const relative = path.relative(parentPath, childPath);
const isSubdir =
relative && !relative.startsWith('..') && !path.isAbsolute(relative);
return isSubdir;
}

function isSameDir(path1: string, path2: string) {
const relative = path.relative(path1, path2);
return !relative;
}

export function getProjectGraphNodeType(
projectRoot: string,
): 'app' | 'e2e' | 'lib' {
Expand Down
4 changes: 0 additions & 4 deletions packages/common/src/lib/versions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@ export const micronautVersion = '4.0.2';
export const kspVersion = '1.8.22-1.0.11';
export const shadowVersion = '8.1.1';

//Linters
export const checkstyleVersion = '10.11.0';
export const ktlintVersion = '0.49.1';

//Jnxplus gradle plugin
export const jnxplusGradlePluginVersion = '0.2.0';
99 changes: 0 additions & 99 deletions packages/internal/generators-files/linters/checkstyle.xml

This file was deleted.

38 changes: 0 additions & 38 deletions packages/internal/generators-files/linters/pmd.xml

This file was deleted.

Loading

0 comments on commit 877814a

Please sign in to comment.