Nothing Special   »   [go: up one dir, main page]

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

normalize special characters in module names to allow variable access #14353

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sgvictorino
Copy link
Contributor
@sgvictorino sgvictorino commented Nov 15, 2024

Fixes #14252

User-Facing Changes

  • Special characters in module names are replaced with underscores when
    importing constants, preventing "expected valid variable name":
> module foo-bar { export const baz = 1 }
> use foo-bar
> $foo_bar.baz
  • "expected valid variable name" errors now include a suggestion list:
> module foo-bar { export const baz = 1 }
> use foo-bar
> $foo-bar
Error: nu::parser::parse_mismatch_with_did_you_mean

  × Parse mismatch during operation.
   ╭─[entry #1:1:1]
 1  $foo-bar;
   · ────┬───
   ·     ╰── expected valid variable name. Did you mean '$foo_bar'?
   ╰────

@sholderbach sholderbach added pr:breaking-change This PR implies a change affecting users and has to be noted in the release notes pr:language This PR makes some language changes labels Nov 15, 2024
@fdncred
Copy link
Collaborator
fdncred commented Nov 15, 2024

@sgvictorino is on fire 🔥!!! We appreciate all your PRs. Thanks.

@WindSoilder
Copy link
Collaborator

Thanks! But there is one thing I'm not sure:

module foo-bar { export const baz = 1 }
use foo-bar
$foo-bar.baz

Personally I think it's better to export use baz variable like $foo_bar.baz, to user, after using foo-bar and using it with $ sign, it's using more like a variable rather than a module name.

@sholderbach
Copy link
Member

How will this play out with use <filename>.nu modules?

@sgvictorino
Copy link
Contributor Author
sgvictorino commented Nov 17, 2024

How will this play out with use <filename>.nu modules?

The filename stem must be a valid module name. Out of the invalid identifier characters, someone might try to name files like foo.bar.nu, but fully qualified access would already be ambiguous with a cell path on $foo.

I'm also fine with normalizing certain symbols to a valid variable name like @WindSoilder prefers. The "did you mean" fuzzy search helps with that UX.

@132ikl
Copy link
Contributor
132ikl commented Nov 19, 2024

I think normalizing would be the best option, since then it can align with typical variable name rules and can possibly catch more cases than just hyphens and the dot issue you bring up.

@WindSoilder
Copy link
Collaborator

Yeah, @sgvictorino can you update the code to use $foo_bar.baz?

@sgvictorino sgvictorino force-pushed the stricter-module-name-parsing branch 2 times, most recently from f89f386 to 99f4337 Compare November 22, 2024 21:56
# User-Facing Changes

- Special characters in module names are replaced with underscores when
  importing constants, preventing "expected valid variable name":

```nushell
> module foo-bar { export const baz = 1 }
> use foo-bar
> $foo_bar.baz
```

- "expected valid variable name" errors now include a suggestion list:

```nushell
> module foo-bar { export const baz = 1 }
> use foo-bar
> $foo-bar
Error: nu::parser::parse_mismatch_with_did_you_mean

  × Parse mismatch during operation.
   ╭─[entry nushell#1:1:1]
 1 │ $foo-bar;
   · ────┬───
   ·     ╰── expected valid variable name. Did you mean '$foo_bar'?
   ╰────
```
@sgvictorino sgvictorino changed the title make module name parsing more strict normalize special characters in module names to allow variable access Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:breaking-change This PR implies a change affecting users and has to be noted in the release notes pr:language This PR makes some language changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exported constants in modules with a dash in the name aren't accessible
5 participants