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

ember/template-no-let-reference #2078

Open
amk221 opened this issue Jan 29, 2024 · 9 comments
Open

ember/template-no-let-reference #2078

amk221 opened this issue Jan 29, 2024 · 9 comments
Labels

Comments

@amk221
Copy link

amk221 commented Jan 29, 2024

Is it ok to disable this rule in tests? This is a contrived test case

let someThing;

hooks.beforeEach(function (assert) {
  someThing = null;
});

test('foo', async function (assert) {
  someThing = 'foo'

  await render(<template>
    <MyComponent @arg={{someThing}} />
  </template>);
});

test('bar', async function (assert) {
  someThing = 'bar'

  await render(<template>
    <MyComponent @arg={{someThing}} />
  </template>);
});
@NullVoxPopuli
Copy link
Contributor

Is it ok to disable this rule in tests?

yea, I'd say so.

@amk221 amk221 closed this as completed Jan 29, 2024
@NullVoxPopuli
Copy link
Contributor

@bmish should we have a config for tests?

@NullVoxPopuli
Copy link
Contributor

Re-opening, as this could affect many

@NullVoxPopuli NullVoxPopuli reopened this Jan 30, 2024
@bmish
Copy link
Member

bmish commented Jan 30, 2024

I'm opposed to adding additional configs. I'd like everything to work properly with simply the recommended config. We have other rules that bail-out in test files.

@bmish bmish added the bug label Jun 15, 2024
@bitxplora
Copy link

The rule can be turned off in the .eslintrc.js file for the files in the test directory; if there is agreement on this, I will work on it.

Note: eslint is migrating to a new configuration format and file name.

@NullVoxPopuli
Copy link
Contributor

NullVoxPopuli commented Oct 9, 2024

Here is what the blueprints should probably use: #2171 (the flat config w/ eslint 9)

The rule can be turned off in the .eslintrc.js file for the files in the test directory;

yeah, we can early-return in the rule after checking the file path, then no one needs to change their eslint config

@bitxplora
Copy link

bitxplora commented Oct 12, 2024

Here is what the blueprints should probably use: #2171 (the flat config w/ eslint 9)

The rule can be turned off in the .eslintrc.js file for the files in the test directory;

yeah, we can early-return in the rule after checking the file path, then no one needs to change their eslint config

If this is the rule, https://github.com/ember-cli/eslint-plugin-ember/blob/master/lib/rules/template-no-let-reference.js

We can get filepath using context.physicalFilename and return if the filepath starts with /tests/ directory.

 ... 

function checkIfWritableReferences(node, scope) {
     // Return early if the filepath starts with '/tests/' using 'context.physicalFilename`
  if (filepath.startsWith('/tests/'))  {
     return;
  }

...
}

I want to get feedback on whether the approach is appropriate.

@NullVoxPopuli
Copy link
Contributor

Ye looks like a good plan

bitxplora added a commit to bitxplora/eslint-plugin-ember that referenced this issue Oct 12, 2024
This allows referencing let variables in the files in the tests
directory without causing linting errors.
@balinterdi
Copy link

Does this have to be linted against because it creates a memory leak?

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

No branches or pull requests

5 participants