-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e90bcb4
commit 0724c00
Showing
3 changed files
with
94 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const fs = require('fs'); | ||
|
||
// Read the ESLint output file | ||
const eslintOutput = JSON.parse(fs.readFileSync('../formatted-eslint-output.json', 'utf8')); | ||
|
||
const messages = ["'event' is not defined.", "'path' is not defined.", "'event' is defined but never used.", "'path' is defined but never used."]; | ||
|
||
// Filter messages with the specific message | ||
const unusedEventMessages = eslintOutput.filter(result => | ||
result.messages.some(message => | ||
message.message === "'path' is not defined." | ||
) | ||
); | ||
|
||
// Extract the lines and columns to remove | ||
const targetLine = unusedEventMessages.flatMap(result => | ||
result.messages | ||
.filter(message => message.message === "'path' is not defined.") | ||
.map(message => ({ | ||
filePath: result.filePath, | ||
line: message.line, | ||
column: message.column, | ||
source: result.source | ||
})) | ||
); | ||
|
||
// Write the lines to remove to a file | ||
fs.writeFileSync('lines-to-remove.json', JSON.stringify(targetLine, null, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const fs = require('fs'); | ||
const linesToRemove = JSON.parse(fs.readFileSync('lines-to-remove.json', 'utf8')); | ||
|
||
// Sort linesToRemove in reverse order based on line and column | ||
linesToRemove.sort((a, b) => { | ||
if (a.filePath !== b.filePath) { | ||
return a.filePath.localeCompare(b.filePath); | ||
} | ||
if (a.line !== b.line) { | ||
return b.line - a.line; | ||
} | ||
return b.column - a.column; | ||
}); | ||
|
||
|
||
module.exports = function(fileInfo, api) { | ||
const j = api.jscodeshift; | ||
const root = j(fileInfo.source); | ||
|
||
// Debugging: Log the file being processed | ||
console.log(`Processing file: ${fileInfo.path}`); | ||
|
||
// Find and remove the unused 'event' variables in reverse order | ||
linesToRemove.forEach(({ filePath, line, column }) => { | ||
// Debugging: Log the file path, line, and column being checked | ||
// console.log(`Checking: ${filePath} at line ${line}, column ${column}`); | ||
|
||
|
||
// remove identifiers matching the line and column from the esLint list of items to remove | ||
// root.find(j.Identifier, { name: 'event' }) | ||
// .filter(path => { | ||
// const start = path.node.loc.start; | ||
// // Debugging: Log the position of the identifier | ||
// if (start.line === line) {console.log(`Found 'event' at line ${start.line}, column ${start.column}`)} | ||
// return start.line === line && start.column === column - 1; | ||
// }) | ||
// .remove(); | ||
|
||
// transform identifiers matching the line and column from the esLint list of items to transform | ||
root.find(j.Identifier, { name: 'path' }) | ||
.filter(p => { | ||
const start = p.node.loc.start; | ||
// Debugging: Log the position of the identifier | ||
if (start.line === line) {console.log(`Found 'path' at line ${start.line}, column ${start.column}`)} | ||
return start.line === line && start.column === column - 1; | ||
}) | ||
.replaceWith(p => { | ||
// Debugging: Log the node being replaced | ||
// console.log(`Replacing 'identifier' at line ${path.node.loc.start.line}, column ${path.node.loc.start.column}`); | ||
return j.memberExpression(j.identifier('window'), j.identifier('path')); | ||
}); | ||
|
||
}); | ||
|
||
return root.toSource(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters