question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule Proposal: disallow the updates of imported bindings

See original GitHub issue

Please describe what the rule should do:

Disallows the updates of imported bindings with ES Modules because such an update will cause runtime errors.

What category of rule is this? (place an “X” next to just one item)

[X] Warns about a potential error (problem)

Provide 2-3 code examples that this rule will warn about:

import mod, { named } from "./mod.mjs"
import * as mod_ns from "./mod.mjs"

mod = 1 // ERROR: 'mod' is readonly.
named = 2 // ERROR: 'named' is readonly.
mod_ns.named = 3 // ERROR: the members of 'mod_ns' is readonly.
mod_ns = {} // ERROR: 'mod_ns' is readonly.

mod++ // ERROR: 'mod' is readonly.
named++ // ERROR: 'named' is readonly.
mod_ns.named++ // ERROR: the members of 'mod_ns' is readonly.
mod_ns++ // ERROR: 'mod_ns' is readonly.

// Known limitation
function test(obj) {
    obj.named = 4 // Not errored because 'obj' is not namespace objects.
}
test(mod_ns) // Not errored because it doesn't know that 'test' updates the member of the argument.

Why should this rule be included in ESLint (instead of a plugin)?

Because this is an essential of the language feature. This rule is very similar to core rules no-const-assign that catches runtime errors.

The rule name may be no-import-assign.

Are you willing to submit a pull request to implement this rule?

Yes.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Sep 9, 2019

New rules can be semver-minor. The only thing that must be semver-major is adding the rule to eslint:recommended.

0reactions
mysticateacommented, Sep 9, 2019

In my feeling, as I enumerated in https://github.com/eslint/eslint/issues/12237#issuecomment-529297666, no-param-reassign is the only exception of similar rules. So I feel there is special reason for the word selection. And overload handling is the one for parameters but not for the others. Therefore, I feel no-param-reassign has chosen the reassign word for overload handling. But it’s not right.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Requirements for Electronic Ruling Requests
Under the newly enhanced eRulings program, the importing community may submit an electronic request for a binding ruling by accessing the ...
Read more >
Importing Rules with Binding Changes - SAP Community
When I import the entire project, there are no errors during import, but the rules with binding changes are not updated.
Read more >
European Commission proposes ban on goods made with ...
As drafted, the new rules would apply to both imported goods and goods made in the European Union. The proposal is expected to...
Read more >
Magnuson-Stevens Fishery Conservation and Management Act
Response: As described in the preamble to the proposed rule, this regulation addresses only the collection of information on imported fish and ...
Read more >
Know the import and export laws and regulations
Exporting and importing rules · Get updates on U.S. and foreign regulations ... No customs duties or taxes will be assessed at the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found