Skip to content

tighter restrictions on alias and def names - #7392

Merged
rgwood merged 2 commits into
nushell:mainfrom
merelymyself:main
Dec 22, 2022
Merged

rgwood merged 2 commits into
nushell:mainfrom
merelymyself:main

Conversation

@merelymyself

Copy link
Copy Markdown
Contributor

Description

Prevent a situation where a def can't be run due to a poor choice of name. Related: #6335. Hashtags, numbers and filesizes are no longer allowed. alias check has been moved because previously alias 123 would be caught but alias "123" would be permitted.

User-Facing Changes

Some definitions can no longer be made, but because they couldn't be run previously anyway, it doesn't really matter.

Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

  • cargo fmt --all -- --check to check standard code formatting (cargo fmt --all applies these changes)
  • cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo test --workspace to check that all tests pass

After Submitting

If your PR had any user-facing changes, update the documentation after the PR is merged, if necessary. This will help us keep the docs up to date.

@webbedspace

Copy link
Copy Markdown
Contributor

high-pitched nasally voice "Hashtag" isn't really the correct name for that ASCII symbol… it's just a "hash"… a "hashtag" is a hash + a tag of text…

));
assert!(actual
.err
.contains("alias name can't be a number, a filesize, or contain a hash"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we could probably say something like "alias name can't start with a number or contain a hash"

Then prevent anything that starts with a number, in case we add support for more number+unit in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The issue I found with that was the command 7z, which is still widely used. If we just disallow anything that starts with a number, custom completions can't be written for that, so I feel just updating when support is added for more number+unit is still better for the end-user.

@sholderbach sholderbach added the notes:breaking-changes Noted in Breaking Changes section label Dec 10, 2022
@sholderbach

Copy link
Copy Markdown
Member

What is the status on this PR? Do we need to take into account more exceptions like with 7z or is this ready to merge?

@rgwood

rgwood commented Dec 17, 2022

Copy link
Copy Markdown
Contributor

I think this is probably good to go, I agree that we should let aliases start with a number because 7z.

Personally I would put the name.contains('#') || name.parse::<bytesize::ByteSize>().is_ok() || name.parse::<f64>().is_ok() check in a helper method instead of repeating it 3x but I don't think that's a blocker.

@fdncred

fdncred commented Dec 22, 2022

Copy link
Copy Markdown
Contributor

it's a good time to land this if we still think it's good to go.

@rgwood
rgwood merged commit 6fc5244 into nushell:main Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:breaking-changes Noted in Breaking Changes section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants