Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle deployment selection inconsistencies #161

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from

Conversation

rahulyadav-57
Copy link
Member

Resolves #49

.filter((file) => {
const fileExtension = getFileExtension(file.name || '');
const isAbiFile =
file.path.startsWith(`${activeProject?.path}/dist`) &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please encapsulate all the logic related to filenames into a separate file.

If there is another place in the code that would need to check if the file is an ABI-file, it would be found there.

The underlying problem is that file paths are usually untyped, and it's unsafe to work with them with String methods. While working with paths as if they were Strings is not avoidable (that's the OS interface to work with files after all), it's possible to at least give proper attention to changes of unsafe code, if it's encapsulated in a separate file.

.map((file) => ({
id: file.id,
name: file.name
.replace('.abi', '')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These strings are repeated several times over the code base, and in case there'll be a change to them, there'll be no way to ensure modification is consistent.

It'd be better to assign this replace action a name and encapsulate all the related strings in a single file.

if (selectedABIPath) {
const correspondingScriptPath = selectedABIPath.replace('.abi', '.ts');

let _selectedContract: string | undefined = selectedABIPath;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is used. _ convention is for variables that are unused, or for private class fields.

const selectedABIPath = activeProject?.selectedContract;

if (selectedABIPath) {
const correspondingScriptPath = selectedABIPath.replace('.abi', '.ts');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • These strings are repeated in other parts of code.
  • The replace goes over the whole string, and .abi can be any part of it. For example, .abi, .abi.foo.cpp or h.abibi.txt.

if (activeProject?.selectedContract) {
setSelectedContract(activeProject.selectedContract);
deployForm.setFieldsValue({ contract: activeProject.selectedContract });
const selectedABIPath = activeProject?.selectedContract;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abbreviations in camel case are handled as regular words.

Here's a review of the reasoning behind it.

The most important part there is that automated tools can only work if rules do not depend on semantics. For example, if there would be a file that exports selectedABIPath, its name by Node.js file naming standards would be selected-a-b-i-path, and linter would enforce that.

if (selectedABIPath) {
const correspondingScriptPath = selectedABIPath.replace('.abi', '.ts');

let _selectedContract: string | undefined = selectedABIPath;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable doesn't have to be mutable. By abstracting the logic into getSelectedContract() it could be just a return.

@verytactical
Copy link
Collaborator

This is open for 3 weeks without progress. Should we close it?

Copy link
Member

@anton-trunov anton-trunov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rahulyadav-57 please resolve the comments

@rahulyadav-57
Copy link
Member Author

I was working on Misti support, so it was delayed. I'll resolve it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants