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

Fix: Add lastToken check at padding-line-between-statements #8748

Conversation

madyankin
Copy link
Contributor

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[X] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

Tell us about your environment

  • ESLint Version: v4.0.0
  • Node Version: v8.1.0
  • npm Version: 5.0.3

What parser (default, Babel-ESLint, etc.) are you using?
babel-eslint

Please show your full configuration:

---
  extends: airbnb-base
  parser: babel-eslint

  settings:
    import/resolver:
      node:
        extensions:
          - .js
          - .ios.js
          - .androis.js
        moduleDirectory:
          - node_modules
          - js

  plugins:
    - babel
    - react
    - import

  parserOptions:
    ecmaVersion: 7
    sourceType: module
    ecmaFeatures:
      jsx: true
      modules: true

  env:
    es6: true
    node: true
    jest: true

  globals:
    __DEV__: true
    fetch: true
    XMLHttpRequest: true

  rules:
    import/no-unresolved:
      - 2
      - { ignore: [ '^[app]' ] }
    import/extensions: 0
    import/no-extraneous-dependencies: 0
    import/prefer-default-export: 0

    strict: [2, 'never']
    no-debugger: 2
    arrow-body-style: 0
    no-return-assign: 0
    no-plusplus: 0
    class-methods-use-this: 0
    no-underscore-dangle: 0

    brace-style:
      - 2
      - stroustrup
      - { allowSingleLine: true }

    template-curly-spacing: [2, 'always']
    array-bracket-spacing: [2, 'always']

    array-element-newline: [2, { multiline: true }]

    key-spacing:
      - 2
      -
        align:
          afterColon: true
          on: value

    padding-line-between-statements:
        - 2
        - { blankLine: 'always', prev: 'block-like', next: '*' }
        - { blankLine: 'always', prev: '*', next: 'block-like' }

        - { blankLine: 'always', prev: '*', next: 'return' }

        - { blankLine: 'always', prev: '*', next: 'function' }
        - { blankLine: 'always', prev: 'function', next: '*' }

        - { blankLine: 'always', prev: ['const', 'let', 'var'], next: '*'}
        - { blankLine: 'any', prev: ['const', 'let', 'var'], next: ['const', 'let', 'var']}
        - { blankLine: 'always', prev: 'expression', next: ['const', 'let', 'var']}

        - { blankLine: 'always', prev: 'import', next: '*'}
        - { blankLine: 'any', prev: 'import', next: 'import'}

    id-length:
      - 2
      - { properties: 'never', exceptions: ['x', 'y', 'i', '_', 'e'] }

    jsx-quotes: [2, 'prefer-single']
    react/jsx-filename-extension: 0
    react/prefer-stateless-function: 0
    react/jsx-uses-react: 2
    react/jsx-uses-vars: 2
    react/jsx-first-prop-new-line: [2, 'multiline']
    react/jsx-indent-props: [2, 2]
    react/react-in-jsx-scope: 2
    react/jsx-curly-spacing: [2, 'always']
    react/jsx-equals-spacing: [2, 'always']
    react/forbid-prop-types:
      - 2
      - forbid: ['any', 'array']
    react/sort-comp:
      - 2
      -
        groups:
          lifecycle:
            - displayName
            - propTypes
            - contextTypes
            - childContextTypes
            - mixins
            - statics
            - defaultProps
            - state
            - constructor
            - getDefaultProps
            - getInitialState
            - getChildContext
            - componentWillMount
            - componentDidMount
            - componentWillReceiveProps
            - shouldComponentUpdate
            - componentWillUpdate
            - componentDidUpdate
            - componentWillLeave
            - componentWillUnmount

What did you do? Please include the actual source code causing the issue.

import AppNavigator from './AppNavigator';

const initialState = AppNavigator.router.getStateForAction(
  AppNavigator.router.getActionForPathAndParams('Login'),
);

export function reducer(state = initialState, action) {
  const nextState = AppNavigator.router.getStateForAction(action, state);

  return nextState || state;
}

What did you expect to happen?
I expected eslint to lint my code

What actually happened? Please include the actual, raw output from ESLint.

$(yarn bin)/eslint js/**/*.js *.js
Cannot read property 'value' of null
TypeError: Cannot read property 'value' of null
    at Object.isClosingBraceToken (/Users/outpunk/Code/App/node_modules/eslint/lib/ast-utils.js:364:17)
    at isBlockLikeStatement (/Users/outpunk/Code/App/node_modules/eslint/lib/rules/padding-line-between-statements.js:96:36)
    at Object.test (/Users/outpunk/Code/App/node_modules/eslint/lib/rules/padding-line-between-statements.js:331:37)
    at match (/Users/outpunk/Code/App/node_modules/eslint/lib/rules/padding-line-between-statements.js:473:41)
    at getPaddingType (/Users/outpunk/Code/App/node_modules/eslint/lib/rules/padding-line-between-statements.js:489:21)
    at Linter.verify (/Users/outpunk/Code/App/node_modules/eslint/lib/rules/padding-line-between-statements.js:551:30)
    at emitOne (events.js:115:13)
    at Linter.emit (events.js:210:7)
    at NodeEventGenerator.applySelector (/Users/outpunk/Code/App/node_modules/eslint/lib/util/node-event-generator.js:265:26)
    at NodeEventGenerator.applySelectors (/Users/outpunk/Code/App/node_modules/eslint/lib/util/node-event-generator.js:292:22)

What changes did you make? (Give an overview)

I have added check for null value of lastToken at isBlockLikeStatement in lib/rules/padding-line-between-statements.js

Is there anything you'd like reviewers to focus on?
No

@eslintbot
Copy link

Thanks for the pull request, @Outpunk! I took a look to make sure it's ready for merging and found some changes are needed:

  • The commit summary must be 72 characters or shorter. Please check out our guide for how to properly format your commit summary and update it on this pull request.

Can you please update the pull request to address these?

(More information can be found in our pull request guide.)

@jsf-clabot
Copy link

jsf-clabot commented Jun 16, 2017

CLA assistant check
All committers have signed the CLA.

@madyankin madyankin force-pushed the type-error-fix-in-padding-line-between-statements branch from 8a1edb4 to f720961 Compare June 16, 2017 08:16
@eslintbot
Copy link

LGTM

@madyankin madyankin force-pushed the type-error-fix-in-padding-line-between-statements branch from f720961 to 4f9b99f Compare June 16, 2017 08:19
@eslintbot
Copy link

LGTM

@gyandeeps
Copy link
Member

gyandeeps commented Jun 16, 2017

Is the issue still present if you just use default parser and not babel-eslint?
Asking because I want to makesure its not an issue with babel-eslint.

@gyandeeps gyandeeps added bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules labels Jun 16, 2017
@madyankin
Copy link
Contributor Author

@gyandeeps Can't reproduce today, with both of the parsers

@madyankin
Copy link
Contributor Author

@gyandeeps reproduced, the same thing with the default parser

@madyankin
Copy link
Contributor Author

@gyandeeps any news?

@platinumazure
Copy link
Member

@Outpunk Can you add a test for this change, which fails without your code change and passes with? Thanks!

@madyankin
Copy link
Contributor Author

@platinumazure I'll try

@kaicataldo kaicataldo added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Jun 30, 2017
@kaicataldo
Copy link
Member

kaicataldo commented Jun 30, 2017

Marking as accepted because it is the same bug as #8839.

@Outpunk Hi! I missed this PR and also made a PR to fix this, though I like your solution better. I'm going to close my PR in favor of this one.

I don't think all my tests need to be ported over because this is a more generic solution (which is why I like it better!). I think the important test from the tests I wrote is to check that this is valid:

{
     code: "function test() {};",
     options: [
         { blankLine: "always", prev: "block-like", next: "block-like" }
     ]
},

The other tests are tied more to my specific implementation, so I don't think you need to add those.

@madyankin
Copy link
Contributor Author

@kaicataldo thanks! I'll add your tests in a couple of days — I'm a bit busy until next week.

@ilyavolodin
Copy link
Member

@Outpunk Friendly ping

@madyankin
Copy link
Contributor Author

madyankin commented Jul 21, 2017 via email

@madyankin madyankin force-pushed the type-error-fix-in-padding-line-between-statements branch from 4f9b99f to 1811a05 Compare July 22, 2017 04:21
@eslintbot
Copy link

LGTM

@madyankin
Copy link
Contributor Author

@platinumazure I've added the test

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for contributing to ESLint!

@kaicataldo
Copy link
Member

Restarting the Travis CI tests because it looks like they timed out.

@not-an-aardvark not-an-aardvark merged commit cdb82f2 into eslint:master Jul 30, 2017
@not-an-aardvark
Copy link
Member

Thanks for contributing!

@madyankin
Copy link
Contributor Author

Thanks for accepting!

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants