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

no-inner-declarations wrongfully fails on exports after the first statement #12

Closed
RDambrosio016 opened this issue Sep 29, 2020 · 10 comments
Labels
C-bug Category: bugs E-easy Fixing/implementing this issue is easy and usually fit for newcomers T-Runner This issue primary relates to the lint runner, rslint_core

Comments

@RDambrosio016
Copy link
Collaborator

I tried this code:

export const foo = [];
export function bar() {}

I expected this to happen: linting passes

Instead this happened::

error[no-inner-declarations]: move this function declaration to program's root
  ┌─ tests\main.mjs:2:8
  │
2 │ export function bar() {}
  │        ^^^^^^^^^^^^^^^^^
  │
  = help: move the declaration to the program root

Meta

rslint -V: rslint 0.1.0

If building from source:
rustc --version --verbose:

rustc 1.48.0-nightly (f68e08933 2020-09-19)
binary: rustc
commit-hash: f68e08933d8f519a9655934fedebbc509661b219
commit-date: 2020-09-19
host: x86_64-pc-windows-msvc
release: 1.48.0-nightly
LLVM version: 11.0

**If
Additional context
Add any other context about the problem here.

@RDambrosio016 RDambrosio016 added C-bug Category: bugs T-Runner This issue primary relates to the lint runner, rslint_core labels Sep 29, 2020
@RDambrosio016 RDambrosio016 added the E-easy Fixing/implementing this issue is easy and usually fit for newcomers label Sep 29, 2020
@Stupremee
Copy link
Member

Stupremee commented Oct 2, 2020

If rslint_parse parses the file as a module, the linting passes. Because in your code (if its parsed as a script), the parent.kind() is ERROR and thus will not be counted as a valid kind. This could be easily fixed by just checking for ERROR in the lint.

@RDambrosio016
Copy link
Collaborator Author

Oh that is true, and this brings up another point, the linter should not tread into ERROR nodes, it should skip them and their children because the data inside is non-sensical

@Stupremee
Copy link
Member

This is going to be complicated, because many lints use .parent() or .children(), which are not guaranteed to not return ERROR.

@RDambrosio016
Copy link
Collaborator Author

that does not matter if the linter does not step into the children of error nodes

@Stupremee
Copy link
Member

Ah yes, that makes sense. Misunderstood your message

@RDambrosio016
Copy link
Collaborator Author

Although the file is .mjs so it should be parsing as module 🤔

@Stupremee
Copy link
Member

Stupremee commented Oct 2, 2020

If I rename it to .mjs and run it, the linting passes

Edit: Nvm it doesn't. 😅 Because EXPORT_DECL is not in the valid kind array.

@RDambrosio016
Copy link
Collaborator Author

haha so the issue is still there, although we caught another issue for ERROR nodes

@RDambrosio016
Copy link
Collaborator Author

Oh haha, that makes sense, its an easy fix

@RDambrosio016
Copy link
Collaborator Author

Fixed in 970df03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bugs E-easy Fixing/implementing this issue is easy and usually fit for newcomers T-Runner This issue primary relates to the lint runner, rslint_core
Projects
None yet
Development

No branches or pull requests

2 participants