Skip to content
Closed
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 lib/configs/flat/recommended.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
},
plugins: {
prettier: prettierPlugin,
'eslint-comments': eslintComments,
'eslint-comments': fixupPluginRules(eslintComments),
import: importPlugin,
'i18n-text': fixupPluginRules(i18nTextPlugin),
'no-only-tests': noOnlyTestsPlugin,
Expand Down
23 changes: 21 additions & 2 deletions lib/formatters/stylish-fixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@ import childProcess from 'node:child_process'
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import SourceCodeFixer from 'eslint/lib/linter/source-code-fixer.js'
import getRuleURI from 'eslint-rule-documentation'

// Simple fix applier to replace the internal ESLint SourceCodeFixer
// which is no longer exported in ESLint v10
function applyFixes(sourceText, messages) {
const fixes = messages
.filter(msg => msg.fix)
.map(msg => msg.fix)
.sort((a, b) => a.range[0] - b.range[0])

let output = sourceText
let offset = 0

for (const fix of fixes) {
const [start, end] = fix.range
output = output.slice(0, start + offset) + fix.text + output.slice(end + offset)
offset += fix.text.length - (end - start)
}

return {output, fixed: fixes.length > 0}
}

export default function stylishFixes(results) {
let output = '\n'
let errors = 0
Expand Down Expand Up @@ -37,7 +56,7 @@ export default function stylishFixes(results) {
}

if (messages.some(msg => msg.fix)) {
const fixResult = SourceCodeFixer.applyFixes(result.source, messages)
const fixResult = applyFixes(result.source, messages)
output += `\n\n$ eslint --fix ${relativePath}\n`
output += diff(result.source, fixResult.output)
}
Expand Down
Loading
Loading