diff --git a/ets2panda/linter/package.json b/ets2panda/linter/package.json index 1dcc5f8e14128fec9f762c28b84e8f1874a89030..9a8bd6eb74db461d7e846933b2c8fa16ec1a9c86 100644 --- a/ets2panda/linter/package.json +++ b/ets2panda/linter/package.json @@ -50,11 +50,12 @@ }, "dependencies": { "commander": "^9.4.0", + "fs-extra": "11.2.0", "homecheck": "file:./homecheck", + "json5": "2.2.3", "log4js": "^6.4.0", - "yup": "^1.4.0", - "fs-extra": "11.2.0", - "json5": "2.2.3" + "readline-sync": "^1.4.10", + "yup": "^1.4.0" }, "devDependencies": { "@eslint/compat": "latest", @@ -67,15 +68,15 @@ "eslint-plugin-n": "^17.9.0", "eslint-plugin-no-null": "^1.0.2", "glob": "^11.0.0", + "nyc": "^15.1.0", "path-scurry": "^2.0.0", "prettier": "latest", "rimraf": "^5.0.10", "shelljs": "^0.8.5", + "source-map": "^0.7.4", "typescript-eslint": "latest", "webpack": "^5.75.0", - "webpack-cli": "^5.0.1", - "nyc": "^15.1.0", - "source-map": "^0.7.4" + "webpack-cli": "^5.0.1" }, "bundleDependencies": [ "log4js", diff --git a/ets2panda/linter/src/cli/CommandLineParser.ts b/ets2panda/linter/src/cli/CommandLineParser.ts index 42e2cf404ba11366bcef40b993c018094f7d1d48..29bf560ef457fa81f428aab0705b4d7ce1d4a15e 100644 --- a/ets2panda/linter/src/cli/CommandLineParser.ts +++ b/ets2panda/linter/src/cli/CommandLineParser.ts @@ -134,6 +134,9 @@ function formIdeInteractive(cmdOptions: CommandLineOptions, commanderOpts: Optio if (commanderOpts.onlyArkts2SyntaxRules) { cmdOptions.linterOptions.onlySyntax = true; } + if (commanderOpts.autofixCheck) { + cmdOptions.linterOptions.autofixCheck = true; + } } function formArkts2Options(cmdOptions: CommandLineOptions, commanderOpts: OptionValues): void { @@ -235,6 +238,7 @@ function createCommand(): Command { option('-o, --output-file-path ', 'path to store all log and result files'). option('--verbose', 'set log level to see debug messages'). option('--enable-interop', 'scan whole project to report 1.1 import 1.2'). + option('--autofix-check', 'confirm whether the user needs automatic repair'). addOption(new Option('--warnings-as-errors', 'treat warnings as errors').hideHelp(true)). addOption(new Option('--no-check-ts-as-source', 'check TS files as third-party libary').hideHelp(true)). addOption(new Option('--no-use-rt-logic', 'run linter with SDK logic').hideHelp(true)). diff --git a/ets2panda/linter/src/cli/LinterCLI.ts b/ets2panda/linter/src/cli/LinterCLI.ts index 438c56756ca19db15cabd61c67cad9b733ce1c98..5501821004af8d732caf31cca7ea10074c56a773 100644 --- a/ets2panda/linter/src/cli/LinterCLI.ts +++ b/ets2panda/linter/src/cli/LinterCLI.ts @@ -16,6 +16,7 @@ import * as fs from 'node:fs'; import * as os from 'node:os'; import * as path from 'node:path'; +import * as readlineSync from 'readline-sync'; import * as readline from 'node:readline'; import type { CommandLineOptions } from '../lib/CommandLineOptions'; import { lint } from '../lib/LinterRunner'; @@ -36,6 +37,13 @@ export function run(): void { } const cmdOptions = parseCommandLine(commandLineArgs); + if (cmdOptions.linterOptions.migratorMode && cmdOptions.linterOptions.autofixCheck) { + const shouldRun = readlineSync.question('Do you want to run the linter and apply migration? (y/n): ').toLowerCase(); + if (shouldRun !== 'y') { + console.log('Linting canceled by user.'); + process.exit(0); + } + } if (cmdOptions.devecoPluginModeDeprecated) { runIdeModeDeprecated(cmdOptions); diff --git a/ets2panda/linter/src/lib/CommandLineOptions.ts b/ets2panda/linter/src/lib/CommandLineOptions.ts index d793e6204454b4cf520c1948013e30db6f293c35..9618e3bdc7edf348e02cf59fa575bc19c95f92b7 100644 --- a/ets2panda/linter/src/lib/CommandLineOptions.ts +++ b/ets2panda/linter/src/lib/CommandLineOptions.ts @@ -33,4 +33,5 @@ export interface CommandLineOptions { outputFilePath?: string; verbose?: boolean; scanWholeProjectInHomecheck?: boolean; + autofixCheck?: boolean; } diff --git a/ets2panda/linter/src/lib/LinterOptions.ts b/ets2panda/linter/src/lib/LinterOptions.ts index 11c2183d5cf0d96c5adc7b4362c71a7edf126bc2..03e41a702ad3600e9cc4d45984a0e87561c08baa 100644 --- a/ets2panda/linter/src/lib/LinterOptions.ts +++ b/ets2panda/linter/src/lib/LinterOptions.ts @@ -47,4 +47,5 @@ export interface LinterOptions { checkTsAndJs?: boolean; inputFiles?: string[]; onlySyntax?: boolean; + autofixCheck?: boolean; }