Skip to content

Commit

Permalink
wip: remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronm-2112 committed Jan 29, 2025
1 parent e90bcb4 commit 0724c00
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 10 deletions.
28 changes: 28 additions & 0 deletions src/renderer/src/scripts/cleanupScripts/linesToRemove.js
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));
56 changes: 56 additions & 0 deletions src/renderer/src/scripts/cleanupScripts/removeUnused.js
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();
};
20 changes: 10 additions & 10 deletions src/renderer/src/scripts/guided-mode/guided-curate-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2679,17 +2679,17 @@ const enableProgressButton = () => {
$("#guided-next-button").prop("disabled", false);
};

const disableElementById = (id) => {
elementToDisable = document.getElementById(id);
elementToDisable.style.opacity = "0.5";
elementToDisable.style.pointerEvents = "none";
};

const enableElementById = (id) => {
elementToEnable = document.getElementById(id);
elementToEnable.style.opacity = "1";
elementToEnable.style.pointerEvents = "auto";
};











const hideEleShowEle = (elementIdToHide, elementIdToShow) => {
let elementToHide = document.getElementById(elementIdToHide);
Expand Down

0 comments on commit 0724c00

Please sign in to comment.