Giter VIP home page Giter VIP logo

babel-jscs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

babel-jscs's Issues

Pre-release v2.0.0 is marked as latest in npm

The pre-release version v2.0.0is marked as the latest stable version in npm.

This leads to problems when installing/updating jscs and babel-jscs:

$ npm install jscs babel-jscs -g # will install jscs 1.13.1 and babel-jscs 2.0.0, two incompatible versions

Jsdoc and destructuring

I use jscs 2.1.0 with {"esnext": true, "jsDoc": {"checkRedundantParams": true}} in WebStorm for inline linting. Jscs highlights param definitions for destructured params (except first) as redundant:

class ServerResponsePage {
  /**
   * Page to show server response.
   * @constructor
   * @param {string} action - response name.
   * @param {string} result - response result. <--- this description is highlighted as redundant
   */
  constructor({query: {action, result}}) {
    // ...
  }
}

Shorthand methods don't cooperate with space checks

The following code:

var o = {
  f() {},
};

with .jscsrc:

{
    "esprima": "./node_modules/babel-jscs",

    "requireSpacesInAnonymousFunctionExpression": {
        "beforeOpeningRoundBrace": true
    }
}

errors:

Missing space before opening round brace at app/modules/services/selection.js :
     1 |var o = {
     2 |    f() {},
--------------^
     3 |};
     4 |

Error running rule disallowSpacesInFunctionDeclaration

disallowSpacesInFunctionDeclaration: Error running rule disallowSpacesInFunctionDeclaration: This is an issue with JSCS and not your codebase.
Please file an issue (with the stack trace below) at: https://github.com/jscs-dev/node-jscs/issues/new
TypeError: Cannot read property 'range' of null
    at Object.JsFile.getFirstNodeToken (/Users/okonet/Projects/adverity/web-app/node_modules/jscs/lib/js-file.js:207:46)
    at /Users/okonet/Projects/adverity/web-app/node_modules/jscs/lib/rules/disallow-spaces-in-function-declaration.js:80:42
    at Array.forEach (native)
    at Object.JsFile.iterateNodesByType (/Users/okonet/Projects/adverity/web-app/node_modules/jscs/lib/js-file.js:426:42)
    at Object.module.exports.check (/Users/okonet/Projects/adverity/web-app/node_modules/jscs/lib/rules/disallow-spaces-in-function-declaration.js:77:14)
    at null.<anonymous> (/Users/okonet/Projects/adverity/web-app/node_modules/jscs/lib/string-checker.js:141:22)
    at Array.forEach (native)
    at StringChecker._checkJsFile (/Users/okonet/Projects/adverity/web-app/node_modules/jscs/lib/string-checker.js:137:31)
    at StringChecker.checkString (/Users/okonet/Projects/adverity/web-app/node_modules/jscs/lib/string-checker.js:117:14)
    at null.<anonymous> (/Users/okonet/Projects/adverity/web-app/node_modules/jscs/lib/checker.js:43:21)

JSX and validateQuoteMarks issue

First, thanks for the great work. I just switched from using esprima-fb to babel-jscs (with jscs-dev/node-jscs#master). I'm experiencing some issues with React/JSX code:

class CardHeader extends PureRender {
  render() {
    return <div className="flex-card__header">{this.props.children}</div>;
  }
}

More specifically, validateQuoteMarks is being triggered (even if I set it to true):

validateQuoteMarks: Invalid quote mark found at src/js/components/CardHeader.react.js :
     6 |class CardHeader extends PureRender {
     7 |  render() {
     8 |    return <div className="flex-card__header">{this.props.children}</div>;
----------------------------------^

I'm using single quotes in my JavaScript, but quotes in JSX, per customary.
I've ESLint and babel-eslint at the same time, but not issue there.
Any hints?
Thanks

Side-effect unescaping HTML from auto-fix

When running using this jscs config:

.jscsrc

{
  "esnext": true,
  "validateQuoteMarks": {
    "mark": "'",
    "escape": true
  }
}

on this code:

import {Component} from 'react';
export default class AnyCode extends Component {
  render() {
    return (
      <div className="highlight">
        <pre>
          <code className="language-html" data-lang="html">
            <span className="nt">&lt;button</span>
          </code>
        </pre>
      </div>
    )
  }
}

Causes the &lt; to become <. This is a side effect of a bug in bablyon in which the Node has the correct rawValue of &lt;, but a value of <. This value property is what the TOKEN gets when used in babel-jscs (see: [email protected] code)

I have not had a chance to try this against the 3.0.0-beta yet, but I wanted to log this in case anyone else was interested in investigating it further.

Tests don't pass, babel-jscs released a breaking change with 5.7.0

Original post on the JSCS repo here: jscs-dev/node-jscs#1567

When I run babel-jscs on my non es6 code, it fails while parsing every file.

Digging a little bit deeper...

index#attachComments is called with >900 tokens, and fails on this line:

} else if (firstComment.start < tokens[0].range[0]) {

If I print tokens[0], I get

{ type: 'String',
  value: 'use strict',
  start: 24,
  end: 36,
  loc: { start: { line: 3, column: 0 }, end: { line: 3, column: 12 } } }

It doesn't have a range, which is why it fails when trying to read index 0 from the undefined property.

Unknown node type ExportDefaultDeclaration

running [email protected] and [email protected]

I got this error

Error: Unknown node type ExportDefaultDeclaration.
    at Controller.traverse (/Users/aarnodo/code/react-kickstart/node_modules/jscs/node_modules/estraverse/estraverse.js:517:31)
    at Object.traverse (/Users/aarnodo/code/react-kickstart/node_modules/jscs/node_modules/estraverse/estraverse.js:709:27)
    at Object.iterate (/Users/aarnodo/code/react-kickstart/node_modules/jscs/lib/tree-iterator.js:9:20)
    at Object.JsFile.iterate (/Users/aarnodo/code/react-kickstart/node_modules/jscs/lib/js-file.js:359:29)
    at Object.JsFile._buildNodeIndex (/Users/aarnodo/code/react-kickstart/node_modules/jscs/lib/js-file.js:752:14)
    at Object.JsFile (/Users/aarnodo/code/react-kickstart/node_modules/jscs/lib/js-file.js:39:28)
    at StringChecker._createJsFileInstance (/Users/aarnodo/code/react-kickstart/node_modules/jscs/lib/string-checker.js:202:16)
    at StringChecker.checkString (/Users/aarnodo/code/react-kickstart/node_modules/jscs/lib/string-checker.js:104:25)
    at null.<anonymous> (/Users/aarnodo/code/react-kickstart/node_modules/jscs/lib/checker.js:43:21)
    at Array.<anonymous> (/Users/aarnodo/code/react-kickstart/node_modules/jscs/node_modules/vow/lib/vow.js:711:39)
    at Immediate.callFns [as _onImmediate] (/Users/aarnodo/code/react-kickstart/node_modules/jscs/node_modules/vow/lib/vow.js:23:35)
    at processImmediate [as _immediateCallback] (timers.js:367:17)

here the source file

export default function () {
  console.log('hello');
};

Few questions

  1. Why do we need to monkeypatch estraverse? Can we not use babel's traversal mechanism which includes the es6 types?
  2. Instead of doing a parent search, why don't we just make jscs a dependency of babel-jscs, and the loc of jscs could be found via require.resolve('jscs')? There's room for trouble since jscs will depend on babel-jscs which depends on jscs. But from my local tests, I haven't seen an issue yet.
  3. What if we just pull in babel's types into tree-iterator.js and extend our custom supplied keys to estraverse? From my local tests, that plus the use of jscs within babel-jscs gets us closer to a stable integration (some tests still fail, but there's progress).

parseError: undefined on function declaraion

For this source file:

var a = 1;
function() {} // will fail
function () {} // will fail

I'm getting following parseError:

./node_modules/.bin/jscs ./babel-jscs-sample.js                   2 ↵
parseError: undefined at ./babel-jscs-sample.js :
     1 |var a = 1;
     2 |function() {} // will fail
----------------^
     3 |function () {} // will fail
     4 |


1 code style error found.

requireSpacesInFunctionExpression issue

Using:

"requireSpacesInFunctionExpression": {
    "beforeOpeningRoundBrace": true
  }

doesn't seem to work for ES6 classes methods

// no problem here
function ciao () {
  console.log('ciao');
}

// error here, despite the space
class Ciao {
  ciao () {
    console.log('ciao');
  }
}

this is the output from the console
screen shot 2015-06-25 at 10 15 40

It works using esprima-fb

Speed

It's a lot slower than the regular parser? Need to investigate if anything can be done. Probably nothing until the CST integration

Issue with nested conditional ternary operator

I have the following code snippet:

let toogleStatus = node.removed ?
    (self.state.addNode !== '' ? !(self.state.addNode.split('_')[0] === node.id) : true)
    : (self.state.removeNode !== '' ? (self.state.removeNode.split('_')[0] === node.id) : false);

Running jscs throws the error "disallowMultipleSpaces: at most 1 spaces required between removeNode and : at filename.js".

The rule I have configured for this is "disallowMultipleSpaces": true.

Running jscs with --fix option results in a very weird code:

let toogleStatus = node.removed ?
    (self.state.addNode !== '' ? !(self.state.addNode.split('_')[0] === node.id) ::: true)
    : (self.state.removeNode : (self.state.removeNode !== '' ? (self.state.removeNode.split('_')[0] === node.id) ::: false);

I am using master branch of node-jscs and babel-jscs version 2.0.0. Did not encounter the issue with other parsers like esprima or esprima-fb.

Any thoughts?

Thanks.

validateQuoteMarks

Moving issue from old repo.

Fails jscs tests / doesn't validate correctly. @deezahyn

disallowSpaceAfterObjectKeys rule is breaking babel stage 1 code

After upgrade to 2.0 this code sample:

let newItem = {
    ...item,
    gridConfig: this.getGridConfigForWidget(item.id),
    appliedFiltersCount: this.getMultiFilters(item.id).length
}

is converted (invalid) to

let newItem = {
    ...item,gridConfig: this.getGridConfigForWidget(item.id),
    appliedFiltersCount: this.getMultiFilters(item.id).length
}

when using -x option. It was working fine with 1.0.3.

Here is the sample output when running the check without -x

disallowSpaceAfterObjectKeys: Illegal space after key at ./js/modules/Dashboard/stores/DashboardStore.js :
   175 |            // This is needed for Angular view to funciton properly
   176 |            let newItem = {
   177 |                ...item,
--------------------------------^
   178 |                gridConfig: this.getGridConfigForWidget(item.id),
   179 |                appliedFiltersCount: this.getMultiFilters(item.id).length

`disallowSpaceAfterObjectKeys` evaluating functions as objects in 2.0.x

After upgrading to 2.0.x, the disallowSpaceAfterObjectKeys rule is now throwing a ton of warnings for me which it didn't used to. Sample:

render () {
------^
    71 |  var classes = {},
    72 |   ACLS = 'Administration-Sidebar';
disallowSpaceAfterObjectKeys: Illegal space after key

It seems that function declarations are now evaluated as object keys.

I want to force a space after the function name and before the parenthesis, but not for objects. ie.

{
    // This spacing is good!
    render () {}
}

// This spacing is bad!
{"test" : "abc"}

This used to work fine in 1.x.x, but in 2.0.x, something has changed.

requireSpacesInFunctionExpression breaks object literal methods

Hi, thanks for this tool! ❤️ ❤️

With latest jscs and babel-jscs, the following code:

var obj = {
    foo () {
    },
};

with the following .jscsrc:

{
  "esnext": true,
  "requireSpacesInFunctionExpression": {
    "beforeOpeningRoundBrace": true,
    "beforeOpeningCurlyBrace": true
  }
}

gives an error:

Missing space before opening round brace at index.js :
     1 |var obj = {
     2 |    foo () {
-----------------^
     3 |    },
     4 |};


1 code style error found.

error after updating to babel@6

node_modules/babel-jscs/acorn-to-esprima.js:2
var tt       = require("babel-core").acorn.tokTypes;
                                          ^

TypeError: Cannot read property 'tokTypes' of undefined
    at Object.<anonymous> (/home/guria/wspace/kg-grid/node_modules/babel-jscs/acorn-to-esprima.js:2:43)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/home/guria/wspace/kg-grid/node_modules/babel-jscs/index.js:1:84)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.