jscs-dev / babel-jscs Goto Github PK
View Code? Open in Web Editor NEW(deprecated) JSCS has merged with ESLint, so check out babel-eslint!
Home Page: https://github.com/babel/babel-eslint
License: MIT License
(deprecated) JSCS has merged with ESLint, so check out babel-eslint!
Home Page: https://github.com/babel/babel-eslint
License: MIT License
The pre-release version v2.0.0
is 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
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}}) {
// ...
}
}
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 |
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)
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
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"><button</span>
</code>
</pre>
</div>
)
}
}
Causes the <
to become <
. This is a side effect of a bug in bablyon
in which the Node
has the correct rawValue
of <
, 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.
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.
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');
};
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.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.
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
It works using esprima-fb
It's a lot slower than the regular parser? Need to investigate if anything can be done. Probably nothing until the CST integration
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.
After upgrading to babel-jscs 2.0.0, I'm getting this error when running grunt-jscs
:
Warning: Unknown node type Super
This is not an issue with babel-jscs 1.0.3.
Any ideas?
Moving issue from old repo.
Fails jscs tests / doesn't validate correctly. @deezahyn
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
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.
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.
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)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.