Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

ter-newline-after-var does not work for nested vars #355

Open
Xenya0815 opened this issue Sep 6, 2018 · 3 comments
Open

ter-newline-after-var does not work for nested vars #355

Xenya0815 opened this issue Sep 6, 2018 · 3 comments

Comments

@Xenya0815
Copy link

Xenya0815 commented Sep 6, 2018

Used versions

TSC: 3.0.3
tslint: 5.11.0
tslint-reslint-rules: 5.4.0

Used tslint.json

{
  "extends": [
    "tslint-eslint-rules"
  ],
  "rules": {
    "ter-newline-after-var": [true, "always"]
  }
}

Linted code

const myFunc = () => {
  const x = 2;
  const y = 3;
  return x + y;
};

Actual behavior

No linter error

Note: Same behavior when I change the arrow function to just function: const myFunc = function() {...}

Expected behavior

The linter error "Expected blank line after variable declarations."

Analysis

If I change the const myFunc to a real function, the linter sees the problem:

function myFunc() {
  const x = 2;
  const y = 3; // ERROR
  return x + y;
};

I'm not experienced with tslinter implementations so I don't know if this information helps:
I found out that the function onNode (file: dist/rules/terNewlineAfterVarRule.js) is called only once with node.kind === ts.SyntaxKind.VariableStatement => true for the outer const.

Thanks for the help!

webschik added a commit to webschik/tslint-eslint-rules that referenced this issue Dec 16, 2018
@Xenya0815
Copy link
Author

@webschik I checked the changes at your repository. It works, thx.
But it breaks the possibility to add additional blank lines:

const foo = 1;  // ERROR: Unexpected blank line after variable declarations.

const bar = 2;

@webschik
Copy link
Contributor

webschik commented Jan 7, 2019

Thanks, @Xenya0815 !
I specifically made this case to trigger the error, but Eslint allows it. I will fix that.

webschik added a commit to webschik/tslint-eslint-rules that referenced this issue Jan 12, 2019
@webschik
Copy link
Contributor

webschik commented Jan 12, 2019

@Xenya0815, I've updated PR

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

No branches or pull requests

2 participants