Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/commands/elixir-compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Compile Elixir projects with Elixir-specific improvements
*/

const ElixirCommandRunner = require('../elixir/command-runner');
const ElixirCommandRunner = require('../elixir/elixir-command-runner-refactored');

async function main() {
const args = process.argv.slice(2);
Expand Down
8 changes: 4 additions & 4 deletions scripts/commands/elixir-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Manage Elixir dependencies with Mix, Hex, and security scanning
*/

const ElixirCommandRunner = require('../elixir/command-runner');
const ElixirCommandRunner = require('../elixir/elixir-command-runner-refactored');
const { defaultErrorHandler } = require('../lib/error-handler');

async function main() {
Expand Down Expand Up @@ -137,7 +137,7 @@ async function runSecurityAudit(runner, _options) {
dep.includes('plug') ||
dep.includes('crypto') ||
dep.includes('ssl') ||
dep.includes('tls'),
dep.includes('tls')
);
if (securityDeps.length > 0) {
console.log(` ⚠️ ${securityDeps.length} security-related dependencies need updates`);
Expand Down Expand Up @@ -169,7 +169,7 @@ async function runSecurityAudit(runner, _options) {
if (auditResult.stdout) {
const lines = auditResult.stdout.split('\n');
const vulnCount = lines.filter(
(line) => line.includes('Vulnerability') || line.includes('CVE') || line.includes('HIGH'),
(line) => line.includes('Vulnerability') || line.includes('CVE') || line.includes('HIGH')
).length;

results.tools.mix_audit = {
Expand All @@ -194,7 +194,7 @@ async function runSecurityAudit(runner, _options) {
securityTools.push('hex.audit');
const lines = hexAuditResult.stdout.split('\n');
const issues = lines.filter(
(line) => line.includes('Vulnerability') || line.includes('found') || line.includes('⚠'),
(line) => line.includes('Vulnerability') || line.includes('found') || line.includes('⚠')
);

results.tools.hex_audit = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/commands/elixir-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Format Elixir code with built-in formatter and Elixir-specific improvements
*/

const ElixirCommandRunner = require('../elixir/command-runner');
const ElixirCommandRunner = require('../elixir/elixir-command-runner-refactored');

async function main() {
const args = process.argv.slice(2);
Expand Down
2 changes: 1 addition & 1 deletion scripts/commands/elixir-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Lint Elixir code with Credo and Elixir-specific improvements
*/

const ElixirCommandRunner = require('../elixir/command-runner');
const ElixirCommandRunner = require('../elixir/elixir-command-runner-refactored');

async function main() {
const args = process.argv.slice(2);
Expand Down
2 changes: 1 addition & 1 deletion scripts/commands/elixir-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Run Elixir tests with ExUnit and Elixir-specific improvements
*/

const ElixirCommandRunner = require('../elixir/command-runner');
const ElixirCommandRunner = require('../elixir/elixir-command-runner-refactored');

async function main() {
const args = process.argv.slice(2);
Expand Down
7 changes: 2 additions & 5 deletions scripts/commands/elixir-typecheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Type check Elixir code with Dialyzer
*/

const ElixirCommandRunner = require('../elixir/command-runner');
const ElixirCommandRunner = require('../elixir/elixir-command-runner-refactored');

async function main() {
const args = process.argv.slice(2);
Expand Down Expand Up @@ -64,10 +64,7 @@ async function main() {
console.error(`\n❌ Type checking failed: ${error.message}`);

// Check if Dialyzer/dialyxir is not installed
if (
error.message.includes('Dialyzer') ||
error.message.includes('dialyxir')
) {
if (error.message.includes('Dialyzer') || error.message.includes('dialyxir')) {
console.log('\n💡 Dialyzer/dialyxir is not configured. Add to mix.exs:');
console.log(' {:dialyxir, "~> 1.4", only: [:dev], runtime: false}');
console.log('\nThen run:');
Expand Down
2 changes: 1 addition & 1 deletion scripts/commands/js-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Build JavaScript/TypeScript projects
*/

const JSCommandRunner = require('../javascript/command-runner');
const JSCommandRunner = require('../javascript/javascript-command-runner-refactored');

async function main() {
try {
Expand Down
2 changes: 1 addition & 1 deletion scripts/commands/js-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Start development server for JavaScript/TypeScript projects
*/

const JSCommandRunner = require('../javascript/command-runner');
const JSCommandRunner = require('../javascript/javascript-command-runner-refactored');

async function main() {
try {
Expand Down
2 changes: 1 addition & 1 deletion scripts/commands/js-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Run linter for JavaScript/TypeScript projects
*/

const JSCommandRunner = require('../javascript/command-runner');
const JSCommandRunner = require('../javascript/javascript-command-runner-refactored');

async function main() {
try {
Expand Down
2 changes: 1 addition & 1 deletion scripts/commands/js-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Run tests for JavaScript/TypeScript projects
*/

const JSCommandRunner = require('../javascript/command-runner');
const JSCommandRunner = require('../javascript/javascript-command-runner-refactored');

async function main() {
try {
Expand Down
2 changes: 1 addition & 1 deletion scripts/commands/ts-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Compile TypeScript projects
*/

const JSCommandRunner = require('../javascript/command-runner');
const JSCommandRunner = require('../javascript/javascript-command-runner-refactored');

async function main() {
try {
Expand Down
2 changes: 1 addition & 1 deletion scripts/commands/ts-typecheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Run TypeScript type checking for TypeScript projects
*/

const JSCommandRunner = require('../javascript/command-runner');
const JSCommandRunner = require('../javascript/javascript-command-runner-refactored');

async function main() {
try {
Expand Down
167 changes: 167 additions & 0 deletions scripts/elixir/elixir-command-runner-modules/code-quality.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
class CodeQuality {
constructor(commandExecutor, loggingUtils) {
this.commandExecutor = commandExecutor;
this.loggingUtils = loggingUtils;
}

async format(options = {}) {
const args = [];

if (options.check) {
args.push('--check-formatted');
}

if (options.dryRun) {
args.push('--dry-run');
}

if (options.files) {
args.push(...options.files.split(','));
}

if (options.verbose) {
args.push('--verbose');
}

try {
return await this.commandExecutor.executeMixCommand('format', args, options);
} catch (error) {
this.suggestFormatFix(error.message);
throw error;
}
}

async lint(options = {}) {
const args = [];

if (options.strict) {
args.push('--strict');
}

if (options.all) {
args.push('--all');
}

if (options.allPriorities) {
args.push('--all-priorities');
}

if (options.format) {
args.push('--format', options.format);
}

if (options.config) {
args.push('--config', options.config);
}

if (options.files) {
args.push(...options.files.split(','));
}

if (options.verbose) {
args.push('--verbose');
}

try {
return await this.commandExecutor.executeMixCommand('credo', args, options);
} catch (error) {
this.suggestLintFix(error.message);
throw error;
}
}

async typecheck(options = {}) {
const args = [];

if (options.noCheck) {
args.push('--no-check');
}

if (options.warnings) {
args.push('--warnings', options.warnings);
}

if (options.format) {
args.push('--format', options.format);
}

if (options.verbose) {
args.push('--verbose');
}

try {
return await this.commandExecutor.executeMixCommand('dialyzer', args, options);
} catch (error) {
this.suggestTypecheckFix(error.message);
throw error;
}
}

suggestFormatFix(errorMessage) {
this.loggingUtils.info('\n💡 Formatting Error Suggestions:');

if (errorMessage.includes('check-formatted')) {
this.loggingUtils.info(' • Files are not properly formatted');
this.loggingUtils.info(' • Run mix format without --check-formatted to fix');
this.loggingUtils.info(' • Check .formatter.exs configuration');
}

if (errorMessage.includes('syntax error')) {
this.loggingUtils.info(' • Fix syntax errors before formatting');
this.loggingUtils.info(' • Check for missing commas, parentheses, or do/end blocks');
this.loggingUtils.info(' • Verify Elixir version compatibility');
}

if (errorMessage.includes('file not found')) {
this.loggingUtils.info(' • Check file paths are correct');
this.loggingUtils.info(' • Ensure files exist in project directory');
this.loggingUtils.info(' • Use relative paths from project root');
}
}

suggestLintFix(errorMessage) {
this.loggingUtils.info('\n💡 Linting Error Suggestions:');

if (errorMessage.includes('Credo')) {
this.loggingUtils.info(' • Install Credo: mix archive.install hex credo');
this.loggingUtils.info(' • Check .credo.exs configuration file');
this.loggingUtils.info(' • Run mix credo --help for available options');
}

if (errorMessage.includes('warning')) {
this.loggingUtils.info(' • Review warnings in context');
this.loggingUtils.info(' • Use --strict for stricter checks');
this.loggingUtils.info(' • Consider fixing high-priority issues first');
}

if (errorMessage.includes('configuration')) {
this.loggingUtils.info(' • Check .credo.exs syntax');
this.loggingUtils.info(' • Verify check configurations');
this.loggingUtils.info(' • Ensure consistent code style rules');
}
}

suggestTypecheckFix(errorMessage) {
this.loggingUtils.info('\n💡 Type Checking Error Suggestions:');

if (errorMessage.includes('Dialyzer')) {
this.loggingUtils.info(' • Install Dialyzer: mix archive.install hex dialyxir');
this.loggingUtils.info(' • Build PLT first: mix dialyzer --plt');
this.loggingUtils.info(' • Check dialyzer.ignore-warnings file');
}

if (errorMessage.includes('type mismatch')) {
this.loggingUtils.info(' • Check function signatures match specifications');
this.loggingUtils.info(' • Review @spec annotations');
this.loggingUtils.info(' • Use dialyzer.ignore-warnings for false positives');
}

if (errorMessage.includes('undefined function')) {
this.loggingUtils.info(' • Ensure all functions are defined or imported');
this.loggingUtils.info(' • Check module dependencies');
this.loggingUtils.info(' • Verify function arity matches');
}
}
}

module.exports = CodeQuality;
Loading
Loading