feat: transition from TSLint to ESLint

This commit is contained in:
Thea Schöbl
2022-06-01 12:00:53 +00:00
parent 73501e0fa3
commit 9430e10387
8 changed files with 1371 additions and 564 deletions

View File

@@ -14,7 +14,7 @@
*/
import {Command} from 'commander';
import {existsSync, readFileSync, writeFileSync} from 'fs';
import {resolve} from 'path';
import path from 'path';
import {cwd} from 'process';
import {
checkCIConfig,
@@ -39,42 +39,42 @@ const currentWorkingDirectory = cwd();
const commander = new Command('openstapps-configuration');
// configure commander
commander
.version(JSON.parse(
readFileSync(resolve(__dirname, '..', 'package.json'))
.toString(),
).version);
// eslint-disable-next-line unicorn/prefer-module
commander.version(JSON.parse(readFileSync(path.resolve(__dirname, '..', 'package.json')).toString()).version);
commander
.option('-p, --path <path>', `Path of project to add files to (${currentWorkingDirectory})`, currentWorkingDirectory)
.option(
'-p, --path <path>',
`Path of project to add files to (${currentWorkingDirectory})`,
currentWorkingDirectory,
)
.option('-r, --replace', 'Whether to replace existing files or not', false)
.parse(process.argv);
// make path absolute
const path = resolve(commander.opts().path);
const projectPath = path.resolve(commander.opts().path);
// check for existing package.json in provided path
if (!existsSync(resolve(path, 'package.json'))) {
throw new Error(`No 'package.json' in '${path}'.`);
if (!existsSync(path.resolve(projectPath, 'package.json'))) {
throw new Error(`No 'package.json' in '${projectPath}'.`);
}
// path to examined package.json
const packageJsonPath = resolve(path, 'package.json');
const packageJsonPath = path.resolve(projectPath, 'package.json');
// read package.json in provided path
const packageJson = JSON.parse(readFileSync(packageJsonPath)
.toString());
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
// check if provided path is this package
if (packageJson.name === '@openstapps/configuration') {
consoleInfo('I\'m not going to check myself!');
consoleInfo("I'm not going to check myself!");
process.exit(0);
}
// whether or not the contents of the package.json were changed
// whether the contents of the package.json were changed
let packageJsonChanged = false;
// whether or not to suggest an overwrite
// whether to suggest an overwrite
let suggestOverwrite = false;
const configuration = getConfiguration(packageJson);
@@ -85,9 +85,9 @@ checkDependencies(rules, packageJson);
checkLicenses(rules, packageJson);
checkConfigurationFilesAreExtended(path);
checkConfigurationFilesAreExtended(projectPath);
suggestOverwrite = suggestOverwrite || checkNeededFiles(rules, path, commander.opts().replace);
suggestOverwrite = suggestOverwrite || checkNeededFiles(rules, projectPath, commander.opts().replace);
const checkedNYCConfiguration = checkNYCConfiguration(rules, packageJson, commander.opts().replace);
@@ -96,16 +96,17 @@ suggestOverwrite = suggestOverwrite || checkedNYCConfiguration[1];
packageJsonChanged = packageJsonChanged || checkScripts(rules, packageJson, commander.opts().replace);
checkContributors(path, packageJson);
checkContributors(projectPath, packageJson);
checkCIConfig(rules, path);
checkCIConfig(rules, projectPath);
checkCopyrightYears(path, 'src');
checkCopyrightYears(projectPath, 'src');
const indentation = 2;
if (packageJsonChanged) {
writeFileSync(resolve(path, 'package.json'), JSON.stringify(packageJson, null, indentation));
// eslint-disable-next-line unicorn/no-null
writeFileSync(path.resolve(projectPath, 'package.json'), JSON.stringify(packageJson, null, indentation));
consoleLog(`Changes were written to '${packageJsonPath}'.`);
}
@@ -114,4 +115,4 @@ if (suggestOverwrite) {
npm run check-configuration -- -r`);
}
consoleLog(`Done checking the configuration in '${path}'.`);
consoleLog(`Done checking the configuration in '${projectPath}'.`);