GithubHelp home page GithubHelp logo

xojs / xo Goto Github PK

View Code? Open in Web Editor NEW
7.6K 57.0 285.0 778 KB

❤️ JavaScript/TypeScript linter (ESLint wrapper) with great defaults

License: MIT License

JavaScript 100.00%
eslint eslint-plugin eslint-rules linter nodejs shareable-configs best-practices unicorns xo code-style

xo's People

Contributors

1000ch avatar andersk avatar bjornstar avatar brandon93s avatar chalkygames123 avatar coreyfarrell avatar dersimn avatar fisker avatar fregante avatar jamestalmage avatar joakimbeng avatar kevinastone avatar kevva avatar litomore avatar luftywiranda13 avatar marionebl avatar noahbrenner avatar not-an-aardvark avatar ntwb avatar omgimalexis avatar pvdlg avatar richienb avatar rosszurowski avatar samverschueren avatar schnittstabil avatar sindresorhus avatar spence-s avatar sterpe avatar tommy-mitchell avatar xhmikosr avatar

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  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  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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xo's Issues

Error when setting `space` without setting `rules` in package.json

If you set the space property without setting the rules property in the xo configuration in the package.json, the following error is thrown:

opts._config.rules.indent = [2, spaces, {SwitchCase: 1}];

TypeError: Cannot set property 'indent' of undefined
    at handleOpts (node_modules/xo/index.js:58:29)

This occurred with the following config:

"xo": {
    "esnext": true,
    "envs": ["browser", "mocha"],
    "space": 2
}

Adjusting the configuration to include an empty rules object fixes it:

"xo": {
    "esnext": true,
    "envs": ["browser", "mocha"],
    "space": 2,
    "rules": {}
}

A way to override the default ignores

Issuehunt badges

Right now it's not possible to lint anything in a fixtures directory, even if you want to. There should be a way to enable that.

I tried this:

{
  "xo": {
    "ignore": [
      "!{test/,}fixture{s,}/**"
    ]
  }
}

But no luck


IssueHunt Summary

pvdlg pvdlg has been rewarded.

Backers (Total: $80.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

Rules not being overridden?

I'm checking parity between xo and eslint warnings and I get 58 warning / errors with xo and 1 with eslint. Obviously, most of these are because xo has its own rules. I'd like to override all of these with my own rules from my shareable config, but can't seem to get that to happen, even individual rules are not being overridden when I use my custom shareable config.

//package.json

  "xo": {
    "envs": [
      "node",
      "mocha"
    ],
    "extend": "myConfig",
    "rules": {}
  }

can I nullify the rules, like above?

Thanks!

Use of react plugin

Hello,

Sorry for this (maybe stupid) question but if I want to use react plugin did I need to npm install eslint-config-xo-react xo ? Or just npm install xo is sufficient ?

Thanks :)

Open files with problems

While not directly related to xo, is there a way to open all files with problems found by xo,

xo app/**/*.js | subl *

… or something like that?

globals under overrides does not work for me

this is my configuration

"xo" : {
    "space" : 4,

    "overrides" : {
      "test" : "test/*.spec.js",
      "globals" : [ "it" , "describe" ]
    }

  }

and I am getting

test/test.spec.js
  8:1  error  "describe" is not defined  no-undef
  9:5  error  "it" is not defined        no-undef

async/await unexpected token / unexpected identifier, but not everywhere

This file passes:

https://github.com/sindresorhus/ava/blob/master/test/fixture/async-await.js

But if I copy it to the root of the project it fails:

screen shot 2015-10-23 at 7 36 49 am

Line 5:

test('async function', async function (t) {

If I take out that test, we get Parsing error: Unexpected identifier for the next test on this line:

test('arrow async function', async t => {

I didn't see any special eslint/xo settings in this project or ava, such as an automatic ignore for /fixtures.

This might be related to avajs/ava#92, or visa versa.

Using `"esnext": true` or `--esnext` throws error

/usr/local/Cellar/nvm/0.25.4/versions/node/v0.12.7/lib/node_modules/xo/cli.js:76
        throw err;
              ^
TypeError: Cannot read property 'type' of undefined
    at /usr/local/Cellar/nvm/0.25.4/versions/node/v0.12.7/lib/node_modules/xo/node_modules/eslint/lib/rules/quote-props.js:116:20
    at Array.forEach (native)
    at checkConsistency (/usr/local/Cellar/nvm/0.25.4/versions/node/v0.12.7/lib/node_modules/xo/node_modules/eslint/lib/rules/quote-props.js:112:25)
    at EventEmitter.ObjectExpression (/usr/local/Cellar/nvm/0.25.4/versions/node/v0.12.7/lib/node_modules/xo/node_modules/eslint/lib/rules/quote-props.js:156:17)
    at EventEmitter.emit (events.js:129:20)
    at Controller.controller.traverse.enter (/usr/local/Cellar/nvm/0.25.4/versions/node/v0.12.7/lib/node_modules/xo/node_modules/eslint/lib/eslint.js:824:25)
    at Controller.__execute (/usr/local/Cellar/nvm/0.25.4/versions/node/v0.12.7/lib/node_modules/xo/node_modules/eslint/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (/usr/local/Cellar/nvm/0.25.4/versions/node/v0.12.7/lib/node_modules/xo/node_modules/eslint/node_modules/estraverse/estraverse.js:495:28)
    at EventEmitter.module.exports.api.verify (/usr/local/Cellar/nvm/0.25.4/versions/node/v0.12.7/lib/node_modules/xo/node_modules/eslint/lib/eslint.js:817:24)
    at processText (/usr/local/Cellar/nvm/0.25.4/versions/node/v0.12.7/lib/node_modules/xo/node_modules/eslint/lib/cli-engine.js:199:27)

As you might have figured out from the paths, I'm using node v0.12.7 (had to make a switch from iojs) and I'm using OS X (Yosemite).
Removing said options will successfully lint, or better said unsuccessfully since it errors on bunch of es2015 syntax.

Add `semicolon` option

Would love to be able to turn off the requirement of semicolons. (I like all the other rules, including tabs, so I can't use feross/standard)

Is this planned/would a PR be accepted?

Local module workflow query

I've installed xo globally and then used xo --init to add xo as a local dependency to my project, as the documentation suggest.

However I'm having issues when referencing xo from within an npm run task, for example;

package.json

"scripts": {
  "lint": "xo *.js **/*.js --space"
}

When runningnpm run lint I'm receiving errors about various packages not being available, initially it was eslint-config-xo;

Error: Cannot read config package: eslint-config-xo
Error: Cannot find module 'eslint-config-xo'

I installed that as a development dependency but was then told;

Error: Cannot find module 'eslint-plugin-babel'

Which I installed, but then received an error message saying that eslint-plugin-no-empty-blocks cannot be found and this has continued indefinitely with various other eslint modules.

It doesn't feel right to have to add every eslint config module to my dev dependencies to allow xo to work locally. Am I doing something wrong?

Notify about incorrect config

As mentioned in issue #15, there is no error handling when reading package.json (index.js:40), it's ignored and execution continues without user knowing what happened.

It would be great to put a message to notify the user something bad happened and maybe even stop the execution. I'm not sure about the last one, but in my opinion, incorrect npm config isn't something one would even want.
I'm willing to work on it after we clarify what exactly should happen.

Consider tweaking `no-unused-vars`

Currently no-unused-vars doesn't allow function arguments that isn't used. This is a problem when used for example with express which checks fn.length to determine what to do.

The following is considered an error:

function (err, req, res, next) {
  res.status(500).send('An error occurred')
}

That's because it doesn't use the next argument. But if I would remove it express would no longer consider this an error handler.

While I do consider it bad to depend on fn.length the reality is that arguable to most used node.js library does it.

no-unused-var can be specified to allow unused arguments, without affecting the other functionallity:

[ 2, { "vars": "all", "args": "none" } ]

Clarification of config in `package.json`

I use spaces, so runnign xo --space works fine.

However, when trying to throw this into my package.json, this doesn't seem to accept args like ESLINT would:

  "xo": {
    "envs": ["node", "mocha"],
    "rules": {
      "indent": [2, 2, {"SwitchCase": 1}],
    }
  }  

This isn't applying two-space indentation.

Am I missing something?

Cannot define `rules` in `overrides`

Config:

"xo": {
  "overrides": [
    {
      "files": "src/**/*.spec.js",
      "rules": {
        "no-unused-expressions": 0
      }
    }
  ],
}

foo.spec.js

...
expect(checkbox.checked).to.be.false

Lint:

error Expected an assignment or function call and instead saw an expression no-unused-expressions

no-unused-vars rule does not work with React components

Latest xo has problems with detecting usage of React components over the code (no-unused-vars). Even though components are used in code, xo reports them as defined but never used.

example.js:

const React = require('react');

const Button = React.createClass({});

const Container = React.createClass({
    render: function () {
        return <Button />;
    }
});

package.json:

{
  "scripts": {
    "test": "xo"
  },
  "devDependencies": {
    "xo": "^0.12.1"
  }
}
$ npm test

screen shot 2016-01-16 at 12 27 31 pm

JSX ES6 Import Support

If I have a JSX file importing a component from another file:

import Menu from 'app/components/menu';

I seem to get the following error:

"Menu" is defined but never used (no-unused-vars)

However I use it in my JSX:

render() {
  return (
    <div>
      {this.state.loggedIn ? <Menu/> : null}
      {this.props.children}
    </div>
  );
}

Add option to use a custom parser

The first one that springs to mind is babel-eslint (for those ES2015+ features). Maybe something like this?

"xo": {
  "parser": "babel-eslint"
}

Ability to indent files

Right now, setting the style to tabs-not-spaces and running xo --fix will result in a mess of mixed tabs and spaces if there were spaces. You also need to run it multiple times, once for each level of tabs that needs fixing.

The reason is that the eslint fix simply fixes the "expected 1 tab indentation" errors which occur at every block indent.

I am not sure that eslint is equipped to handle the possibly correct fix, which is to give an error on each line that does not have the exact required number of tabs/spaces. This possible fix also impacts non-uniform indentation, so not sure if that's desirable

So possibly XO needs to help out a little with a whitespace conversion pre-run and a recursive run until all the whitespace errors are resolved.

Nested ternaries are just misunderstood.

So I just made a comment here about consistent-this hindering actual functionality - something code styling should do conservatively. Here is something else pretty relevant.

Ternary operations can be performed safely and visibly if nested. As well, there now becomes an issue of branching.

Take the following code:

result.file = opts.dash ? '-' : platform === 'linux' ?
    '/dev/stdin' : '/proc/self/fd/0';

or even this

result.file = opts.dash
    ? '-'
    : platform === 'linux'
        ? '/proc/self/fd/0'
        : '/dev/stdin';

But this results in the following error:

index.js
  27:17  error  Do not nest ternary expressions  no-nested-ternary

Seriously? Here is the alternative.

var inputPath = platform === 'linux' ? '/dev/stdin' : '/proc/self/fd/0';
result.file = opts.dash ? '-' : inputPath;

Which is not correct logic (inputPath should only be evaluated if opts.dash is not truthy).

The other alternative is

var inputPath;
if (opts.dash) {
    inputPath = '-';
} else {
    inputPath = platform === 'linux' ? '/dev/stdin' : '/proc/self/fd/0';
}

Which, come on, seriously? >.> So unnecessary. A nested ternary operation was just fine and readable. I understand this is something I can disable in the package.json but I want to be as, uh... "orthodox" as possible. Plus, turning it off will not (should not) interfere with any existing code.

Add ability to ignore directories

Issuehunt badges

joakimbeng/unistyle@4dfa6bc#commitcomment-13087626

Right now you have to do directory/** to ignore all files in a directory, but would be nice, and probably more natural, if you could ignore a directroy directly by using directroy.


IssueHunt Summary

sindresorhus sindresorhus has been rewarded.

Backers (Total: $60.00)

Submitted pull Requests


Tips

XO config in package.json is ignored when eslintConfig is also present

The problem I have is quite simple: my package.json contains a XO configuration, but when eslintConfig is also added to package.json, the last one take precedence over XO.

{
    "name": "my-awesome-project",
    "eslintConfig": {
        "extends": ["xo", "xo-react"]
    },
    "xo": {
        "esnext": true
    }
}

This configuration will load the XO defaults options, but the esnext option will be ignored. In order to fix this, https://github.com/sindresorhus/xo/blob/master/index.js#L66 needs to allow the extends option to also include the eslintConfig.

Or, even better, I want to be able to specify the extends option straight into XO, like this:

{
    "name": "my-awesome-project",
    "xo": {
        "esnext": true,
        "extends": ["xo-react"]
    }
}

which is equivalent of

{
    "name": "my-awesome-project",
    "xo": {
        "extends": ["esnext", "xo-react"]
    }
}

consistent-this break when preventing nested shadowing

The consistent-this rule will throw in this case:

obj.foo = function () {
  var self = this;

  return through.obj(function () {
    var stream = this; // can't use self here or we'll shadow our previous variable
  });
};

Looks like a pretty frequent pattern we encounter in node code.

We can probably work around the rule in a couple ways, but sometime it won't work to keep context or bind arguments.

Multiple config files for subdirectories

i have a js/ folder where i want to lint with

"esnext": true,
"envs": [
"browser"
]

and then i have my gulpfile folder where i want to lint with

"esnext": false,
"envs": []

this works with .jshint files because i can have multiple of them in the different folders. but with xo the configuration is stored in the package.json which i tried duplicating with different rules into the different folders but it didn't work.

so i'm wondering if theres a solution already? seems like a common case.

Make `radix` a warning

The rule radix requires that parseInt has the second parameter, a radix. It is intended to disallow octal notation, but has the side effect of not allowing auto base-10/base-16 determination in the event the second parameter is absent.

Could we make it a warning?

inline configuration not working for exported variables

In jshint and eslint you can configure exported variables with inline comments. in the XO linter the exported configuration that is described here: http://eslint.org/docs/rules/no-unused-vars.html doesnt seem to work. the /* globals */ configuration works fine however so it doesnt seem to be an issue of inline configurations in general.

/* exported Model */
var Model = 13;

linting it from the terminal with xo file.js thorws the error:
3:5 error "Model" is defined but never used no-unused-vars

i tried to lint the same file with the current eslint linter. that one worked fine. it threw an error without the /* exported Model */, and worked when i plugged it back in.

Badge

Need a badge so projects can let contributors know which code style the project uses.

I'm probably gonna do something custom, like I did for awesome.

I won't get to this in the near term, so for now I would recommend using this:

XO code style

[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)

npm package depend on github

When I install some npm packages, there are messages like:

npm ERR! git fetch -a origin (git://github.com/sindresorhus/xo.git) fatal: read error: ...

Please don't access anything other than NPM registry. Since NPM is not only used in Internet, but also in some private network where there is no access to github.

Unable to customize certain rules via shareable config

Issuehunt badges

Using latest xo (master branch), I'm unable to customize babel/object-curly-spacing rule via shareable config.

package.json:

{
  "extends": "my-config"
}

my-config:

{
  "rules": {
    "babel/object-curly-spacing": 0
  }
}

file.js:

{ key: 'value' }

Given these files, xo throws error:

screen shot 2016-01-08 at 10 18 49 pm

If I override babel/object-curly-spacing in package.json, it works as expected and I no longer get errors:

{
  "rules": {
    "babel/object-curly-spacing": 0
  }
}

Related: https://github.com/sindresorhus/xo/blob/master/options-manager.js#L98

There is a $60.00 open bounty on this issue. Add more on Issuehunt.

Fly XO?

Not trying to shamelessly plug my own stuff, but would be nice to have fly-xo included in the plugins section since there is one for fly-ava in AVA's.

If not, no problem 👍

ESLint 2

I'm working on upgrading to ESLint 2. I've already upgraded eslint-config-xo with required changes and some new rules.

I've hit two issues. Tests don't pass and not exactly sure why. And it seems to be a problem with babel-eslint as async functions no longer parse (Just try running latest master on boxen-cli). Would appreciate some help getting this sorted out as I'm out of time and won't be able to get to this right now.

Stack trace for the failing tests:

TypeError: /Users/sindresorhus/dev/xo/test/options-manager.js: Cannot read property 'start' of undefined
    at /Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/whitespace.js:29:19
    at Whitespace._findToken (/Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/whitespace.js:99:30)
    at Whitespace.getNewlinesBefore (/Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/whitespace.js:28:22)
    at CodeGenerator.printComment (/Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/printer.js:321:34)
    at CodeGenerator.printComments (/Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/printer.js:377:12)
    at CodeGenerator.printLeadingComments (/Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/printer.js:231:10)
    at CodeGenerator.print (/Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/printer.js:81:10)
    at CodeGenerator.printJoin (/Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/printer.js:193:12)
    at CodeGenerator.printList (/Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/printer.js:258:17)
    at CodeGenerator.ObjectExpression (/Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/generators/types.js:48:10)
    at CodeGenerator._print (/Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/printer.js:155:17)
    at CodeGenerator.print (/Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/printer.js:91:10)
    at CodeGenerator.printJoin (/Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/printer.js:193:12)
    at CodeGenerator.printList (/Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/printer.js:258:17)
    at CodeGenerator.CallExpression (/Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/generators/expressions.js:142:8)
    at CodeGenerator._print (/Users/sindresorhus/dev/xo/node_modules/babel-generator/lib/printer.js:155:17)
From previous event:
    at Api.run (/Users/sindresorhus/dev/xo/node_modules/ava/api.js:148:4)
    at Object.<anonymous> (/Users/sindresorhus/dev/xo/node_modules/ava/cli.js:115:5)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3

Fix doesn't fix all fixable issues

Fix is awesome but it doesn't add e.g. trailing commas or fix indentation. I presume these need to be fixed in the eslint plugins? Any hints?

i might suggest that not caring about code style or formatting is a better way to go

i might suggest that not caring about code style/formatting is a better way to go
why people get so hung up on something so pointless i would not know
code is a big messy garden/wilderness
so many people will do it so many ways
parser doesn't care, why should i? i don't uses spaces or tabs
what do they do? why even bother typing them in
if you are reading code you are kind of lost
readability and maintainability is a myth
who cares less -- wins

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.