Skip to content

Commit

Permalink
Fix import paths and error output (#6)
Browse files Browse the repository at this point in the history
* fix import paths and error output

* fix import paths and error output
  • Loading branch information
cjmarkham authored Aug 30, 2024
1 parent 0d96348 commit 2c65262
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
24 changes: 20 additions & 4 deletions src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export const outputErrors = (errors: Map<string, Array<LintError>>, logger: Logg

errors.forEach((lintErrors: Array<LintError>, file: string): void => {
let output = `\n${chalk.underline(file)}`
let maxMessageLength = lintErrors.reduce((a, b) => (a.message.length < b.message.length ? b : a)).message.length

lintErrors.forEach((err: LintError) => {
let color = chalk.yellow
Expand All @@ -44,11 +43,24 @@ export const outputErrors = (errors: Map<string, Array<LintError>>, logger: Logg
totalWarns += 1
}

const errorWithLongestMessage = lintErrors.reduce((a, b) => (a.message.length < b.message.length ? b : a))
const errorWithLongestLocation = lintErrors.reduce((a, b) =>
a.location.column.toString().length + a.location.line.toString().length <
b.location.column.toString().length + b.location.line.toString().length
? b
: a,
)
const maxMessageLength = errorWithLongestMessage.message.length
const maxLocationLength =
errorWithLongestLocation.location.column.toString().length +
errorWithLongestLocation.location.line.toString().length

const location = (err.location.line + ':' + (err.location.column || 0)).toString().padEnd(maxLocationLength + 1)
output += [
'\n',
`${(err.location.line + ':' + ((err.location.column || 0) - 1)).toString()} ${color(err.severity)}`,
`${location} ${color(err.severity).padEnd(5)} `,
// TODO: Fix this padStart mess
err.message.padEnd(maxMessageLength + 4).padStart(70),
err.message.padEnd(maxMessageLength + 1),
chalk.gray(err.rule),
].join('')
})
Expand All @@ -61,6 +73,10 @@ export const outputErrors = (errors: Map<string, Array<LintError>>, logger: Logg
if (!totalErrors) {
color = chalk.bold.yellow
}
logger.info(color(`\nx ${totalErrors + totalWarns} problems (${totalErrors} error(s), ${totalWarns} warning(s))`))
logger.info(
color(
`\nx ${totalErrors + totalWarns} problems (${totalErrors} error${totalErrors ? 's' : ''}, ${totalWarns} warning${totalWarns ? 's' : ''})`,
),
)
}
}
3 changes: 1 addition & 2 deletions src/rule.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { GherkinKeywordNumericals, RuleArguments, RuleDefinition, Severity, Switch } from './config'
import path from 'node:path'
import { GherkinDocument } from '@cucumber/messages'
import { ConfigError, LintError } from './error'

Expand All @@ -24,7 +23,7 @@ export class Rule {
}

public load = async (): Promise<void> => {
this.ruleDefinition = await import(path.resolve(`./src/rules/${this.name}.ts`))
this.ruleDefinition = await import(`./rules/${this.name}.ts`)
}

private parseRule = (): void => {
Expand Down

0 comments on commit 2c65262

Please sign in to comment.