Giter VIP home page Giter VIP logo

xo's Introduction


XO


JavaScript/TypeScript linter (ESLint wrapper) with great defaults

Coverage Status XO code style

Opinionated but configurable ESLint wrapper with lots of goodies included. Enforces strict and readable code. Never discuss code style on a pull request again! No decision-making. No .eslintrc to manage. It just works!

It uses ESLint underneath, so issues regarding built-in rules should be opened over there.

XO requires your project to be ESM.

Highlights

Install

npm install xo --save-dev

You must install XO locally. You can run it directly with $ npx xo.

JSX is supported by default, but you'll need eslint-config-xo-react for React specific linting. Vue components are not supported by default. You'll need eslint-config-xo-vue for specific linting in a Vue app.

Usage

$ xo --help

  Usage
    $ xo [<file|glob> ...]

  Options
    --fix             Automagically fix issues
    --reporter        Reporter to use
    --env             Environment preset  [Can be set multiple times]
    --global          Global variable  [Can be set multiple times]
    --ignore          Additional paths to ignore  [Can be set multiple times]
    --space           Use space indent instead of tabs  [Default: 2]
    --no-semicolon    Prevent use of semicolons
    --prettier        Conform to Prettier code style
    --node-version    Range of Node.js version to support
    --plugin          Include third-party plugins  [Can be set multiple times]
    --extend          Extend defaults with a custom config  [Can be set multiple times]
    --open            Open files with issues in your editor
    --quiet           Show only errors and no warnings
    --extension       Additional extension to lint [Can be set multiple times]
    --cwd=<dir>       Working directory for files
    --stdin           Validate/fix code from stdin
    --stdin-filename  Specify a filename for the --stdin option
    --print-config    Print the ESLint configuration for the given file

  Examples
    $ xo
    $ xo index.js
    $ xo *.js !foo.js
    $ xo --space
    $ xo --env=node --env=mocha
    $ xo --plugin=react
    $ xo --plugin=html --extension=html
    $ echo 'const x=true' | xo --stdin --fix
    $ xo --print-config=index.js

  Tips
    - Add XO to your project with `npm init xo`.
    - Put options in package.json instead of using flags so other tools can read it.

Default code style

Any of these can be overridden if necessary.

  • Tab indentation (or space)
  • Semicolons (or not)
  • Single-quotes
  • Trailing comma for multiline statements
  • No unused variables
  • Space after keyword if (condition) {}
  • Always === instead of ==

Check out an example and the ESLint rules.

Workflow

The recommended workflow is to add XO locally to your project and run it with the tests.

Simply run $ npm init xo (with any options) to add XO to your package.json or create one.

Before/after

 {
 	"name": "awesome-package",
 	"scripts": {
-		"test": "ava",
+		"test": "xo && ava"
 	},
 	"devDependencies": {
-		"ava": "^3.0.0"
+		"ava": "^3.0.0",
+		"xo": "^0.41.0"
 	}
 }

Then just run $ npm test and XO will be run before your tests.

Config

You can configure XO options with one of the following files:

  1. As JSON in the xo property in package.json:
{
	"name": "awesome-package",
	"xo": {
		"space": true
	}
}
  1. As JSON in .xo-config or .xo-config.json:
{
	"space": true
}
  1. As a JavaScript module in .xo-config.js or xo.config.js:
module.exports = {
	space: true
};
  1. For ECMAScript module (ESM) packages with "type": "module", as a JavaScript module in .xo-config.cjs or xo.config.cjs:
module.exports = {
	space: true
};

Globals and rules can be configured inline in files.

envs

Type: string[]
Default: ['es2021', 'node']

Which environments your code is designed to run in. Each environment brings with it a certain set of predefined global variables.

globals

Type: string[]

Additional global variables your code accesses during execution.

ignores

Type: string[]

Some paths are ignored by default, including paths in .gitignore and .eslintignore. Additional ignores can be added here.

space

Type: boolean | number
Default: false (tab indentation)

Set it to true to get 2-space indentation or specify the number of spaces.

This option exists for pragmatic reasons, but I would strongly recommend you read "Why tabs are superior".

rules

Type: object

Override any of the default rules. See the ESLint docs for more info on each rule.

Disable a rule in your XO config to turn it off globally in your project.

Example using package.json:

{
	"xo": {
		"rules": {
			"unicorn/no-array-for-each": "off"
		}
	}
}

You could also use .xo-config.json or one of the other config file formats supported by XO.

Please take a moment to consider if you really need to use this option.

semicolon

Type: boolean
Default: true (Semicolons required)

Set it to false to enforce no-semicolon style.

prettier

Type: boolean
Default: false

Format code with Prettier.

Prettier options will be based on your Prettier config. XO will then merge your options with its own defaults:

To stick with Prettier's defaults, add this to your Prettier config:

module.exports = {
	trailingComma: 'es5',
	singleQuote: false,
	bracketSpacing: true,
};

If contradicting options are set for both Prettier and XO, an error will be thrown.

nodeVersion

Type: string | boolean
Default: Value of the engines.node key in the project package.json

Enable rules specific to the Node.js versions within the configured range.

If set to false, no rules specific to a Node.js version will be enabled.

plugins

Type: string[]

Include third-party plugins.

extends

Type: string | string[]

Use one or more shareable configs or plugin configs to override any of the default rules (like rules above).

extensions

Type: string[]

Allow more extensions to be linted besides .js, .jsx, .mjs, and .cjs as well as their TypeScript equivalents .ts, .tsx, .mts and .cts. Make sure they're supported by ESLint or an ESLint plugin.

settings

Type: object

Shared ESLint settings exposed to rules.

parser

Type: string

ESLint parser. For example, @babel/eslint-parser if you're using language features that ESLint doesn't yet support.

processor

Type: string

ESLint processor.

webpack

Type: boolean | object Default: false

Use eslint-import-resolver-webpack to resolve import search paths. This is enabled automatically if a webpack.config.js file is found.

Set this to a boolean to explicitly enable or disable the resolver.

Setting this to an object enables the resolver and passes the object as configuration. See the resolver readme along with the webpack documentation for more information.

TypeScript

XO will automatically lint TypeScript files (.ts, .mts, .cts, .d.ts and .tsx) with the rules defined in eslint-config-xo-typescript#use-with-xo.

XO will handle the @typescript-eslint/parser project option automatically even if you don't have a tsconfig.json in your project.

GitHub Actions

XO uses a different formatter when running in a GitHub Actions workflow to be able to get inline annotations. XO also disables warnings here.

Note: For this to work, the setup-node action must be run before XO.

Config Overrides

XO makes it easy to override configs for specific files. The overrides property must be an array of override objects. Each override object must contain a files property which is a glob string, or an array of glob strings, relative to the config file. The remaining properties are identical to those described above, and will override the settings of the base config. If multiple override configs match the same file, each matching override is applied in the order it appears in the array. This means the last override in the array takes precedence over earlier ones. Consider the following example:

{
	"xo": {
		"semicolon": false,
		"space": 2,
		"overrides": [
			{
				"files": "test/*.js",
				"space": 3
			},
			{
				 "files": "test/foo.js",
				 "semicolon": true
			}
		]
	}
}
  • The base configuration is simply space: 2, semicolon: false. These settings are used for every file unless otherwise noted below.

  • For every file in test/*.js, the base config is used, but space is overridden with 3. The resulting config is:

{
	"semicolon": false,
	"space": 3
}
  • For test/foo.js, the base config is first applied, followed the first overrides config (its glob pattern also matches test/foo.js), finally the second override config is applied. The resulting config is:
{
	"semicolon": true,
	"space": 3
}

Tips

Using a parent's config

If you have a directory structure with nested package.json files and you want one of the child manifests to be skipped, you can do so by ommiting the xo property in the child's package.json. For example, when you have separate app and dev package.json files with electron-builder.

Monorepo

Put a package.json with your config at the root and omit the xo property in the package.json of your bundled packages.

Transpilation

If some files in your project are transpiled in order to support an older Node.js version, you can use the config overrides option to set a specific nodeVersion to target your sources files.

For example, if your project targets Node.js 8 but you want to use the latest JavaScript syntax as supported in Node.js 12:

  1. Set the engines.node property of your package.json to >=8
  2. Configure Babel to transpile your source files (in source directory in this example)
  3. Make sure to include the transpiled files in your published package with the files and main properties of your package.json
  4. Configure the XO overrides option to set nodeVersion to >=12 for your source files directory
{
	"engines": {
		"node": ">=12"
	},
	"scripts": {
		"build": "babel source --out-dir distribution"
	},
	"main": "distribution/index.js",
	"files": [
		"distribution/**/*.js"
	],
	"xo": {
		"overrides": [
			{
				"files": "source/**/*.js",
				"nodeVersion": ">=16"
			}
		]
	}
}

This way your package.json will contain the actual minimum Node.js version supported by your published code, but XO will lint your source code as if it targets Node.js 16.

Including files ignored by default

To include files that XO ignores by default, add them as negative globs in the ignores option:

{
	"xo": {
		"ignores": [
			"!vendor/**"
		]
	}
}

FAQ

What does XO mean?

It means hugs and kisses.

Why not Standard?

The Standard style is a really cool idea. I too wish we could have one style to rule them all! But the reality is that the JS community is just too diverse and opinionated to create one code style. They also made the mistake of pushing their own style instead of the most popular one. In contrast, XO is more pragmatic and has no aspiration of being the style. My goal with XO is to make it simple to enforce consistent code style with close to no config. XO comes with my code style preference by default, as I mainly made it for myself, but everything is configurable.

Why not ESLint?

XO is based on ESLint. This project started out as just a shareable ESLint config, but it quickly grew out of that. I wanted something even simpler. Just typing xo and be done. No decision-making. No config. I also have some exciting future plans for it. However, you can still get most of the XO benefits while using ESLint directly with the ESLint shareable config.

Editor plugins

Build-system plugins

Configs

Support

Related

Badge

Show the world you're using XO → XO code style

[![XO code style](https://shields.io/badge/code_style-5ed9c7?logo=xo&labelColor=gray)](https://github.com/xojs/xo)

Or customize the badge.

You can also find some nice dynamic XO badges on badgen.net.

Team

Former

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

xo's Issues

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?

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?

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" } ]

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.

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.

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

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.

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

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.

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?

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.

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?

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

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.

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>
  );
}

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 :)

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.

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!

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.

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?

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?

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

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

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": {}
}

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.

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

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"
}

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 👍

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

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"]
    }
}

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.

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)

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.