Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: xojs/xo
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a343eb43e3eda331b7f6bbc8d74fb094d1f8ac08
Choose a base ref
...
head repository: xojs/xo
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ab16df288360c3adc02efa5008b0acaf8c3e4a01
Choose a head ref

Commits on Sep 1, 2015

  1. Bump ava and xo

    joakimbeng committed Sep 1, 2015
    Copy the full SHA
    7413355 View commit details
  2. Copy the full SHA
    5c79ee6 View commit details

Commits on Sep 2, 2015

  1. Merge pull request #19 from joakimbeng/master

    Using babel-eslint as parser for esnext
    sindresorhus committed Sep 2, 2015
    Copy the full SHA
    6435d53 View commit details
  2. bump deps

    sindresorhus committed Sep 2, 2015
    Copy the full SHA
    c14dce1 View commit details

Commits on Sep 3, 2015

  1. Copy the full SHA
    4fc25f4 View commit details
  2. Copy the full SHA
    d2a20bc View commit details
  3. promisify the API

    sindresorhus committed Sep 3, 2015
    Copy the full SHA
    7f5d52c View commit details
  4. xo-init@0.3.0

    sindresorhus committed Sep 3, 2015
    Copy the full SHA
    03cf6b4 View commit details
  5. readme tweaks

    sindresorhus committed Sep 3, 2015
    Copy the full SHA
    6176af6 View commit details
  6. 0.8.0

    sindresorhus committed Sep 3, 2015
    Copy the full SHA
    c5a884d View commit details
  7. readme tweaks

    sindresorhus committed Sep 3, 2015
    Copy the full SHA
    35c3685 View commit details

Commits on Sep 11, 2015

  1. pass options to lintText from cli

    Closes #24
    floatdrop committed Sep 11, 2015
    Copy the full SHA
    4ae1e17 View commit details

Commits on Sep 13, 2015

  1. Merge pull request #25 from floatdrop/master

    pass options to lintText from cli
    sindresorhus committed Sep 13, 2015
    Copy the full SHA
    1e72068 View commit details

Commits on Sep 14, 2015

  1. deep extend the config

    sindresorhus committed Sep 14, 2015
    Copy the full SHA
    1e9b9f4 View commit details
  2. Copy the full SHA
    0a61887 View commit details
  3. bump deps

    sindresorhus committed Sep 14, 2015
    Copy the full SHA
    625efd5 View commit details
  4. enable JSX support

    sindresorhus committed Sep 14, 2015
    Copy the full SHA
    c0847ee View commit details
  5. Copy the full SHA
    0d1cd7f View commit details
  6. 0.9.0

    sindresorhus committed Sep 14, 2015
    Copy the full SHA
    29951ee View commit details
  7. don't return in global scope

    for ES2015 compatibility
    sindresorhus committed Sep 14, 2015
    Copy the full SHA
    61a961f View commit details
  8. ES2015ify the tests

    sindresorhus committed Sep 14, 2015
    Copy the full SHA
    c9e089d View commit details

Commits on Sep 22, 2015

  1. Copy the full SHA
    731e1a7 View commit details

Commits on Sep 28, 2015

  1. Merge pull request #29 from sindresorhus/vim

    Add documentation about using XO with Vim
    sindresorhus committed Sep 28, 2015
    Copy the full SHA
    e98bc61 View commit details

Commits on Oct 3, 2015

  1. add link to TextMate 2 bundle

    claylo committed Oct 3, 2015
    Copy the full SHA
    d747f41 View commit details
  2. Merge pull request #33 from claylo/textmate-bundle

    Add link to TextMate 2 bundle
    sindresorhus committed Oct 3, 2015
    Copy the full SHA
    efeec63 View commit details

Commits on Oct 6, 2015

  1. fix broken link for ignored paths

    Use a commit hash instead of `master`
    antleblanc committed Oct 6, 2015
    Copy the full SHA
    76decd1 View commit details
  2. Merge pull request #36 from antleblanc/patch-1

    fix broken link for ignored paths
    kevva committed Oct 6, 2015
    Copy the full SHA
    cf0a8d0 View commit details

Commits on Oct 16, 2015

  1. Copy the full SHA
    0ffac2d View commit details
  2. Merge pull request #37 from SamVerschueren/vscode

    Added vscode editor plugin
    sindresorhus committed Oct 16, 2015
    Copy the full SHA
    d08b60c View commit details

Commits on Oct 19, 2015

  1. Add support for plugins

    Fixes #30.
    kevva committed Oct 19, 2015
    Copy the full SHA
    e2e2cd9 View commit details
  2. Copy the full SHA
    260284d View commit details
  3. Merge pull request #39 from blainsmith/master

    Adding metalsmith-xo to Build Systems
    sindresorhus committed Oct 19, 2015
    Copy the full SHA
    4ae432c View commit details

Commits on Oct 20, 2015

  1. Merge pull request #35 from sindresorhus/plugins

    Add support for plugins
    sindresorhus committed Oct 20, 2015
    Copy the full SHA
    1547ae2 View commit details
  2. Copy the full SHA
    5052d14 View commit details
  3. Merge pull request #41 from sindresorhus/no-extend-native

    Use `no-use-extend-native` plugin by default
    sindresorhus committed Oct 20, 2015
    Copy the full SHA
    afa3f5b View commit details

Commits on Oct 22, 2015

  1. add stable node to .travis.yml

    vdemedes committed Oct 22, 2015
    Copy the full SHA
    aa4edcd View commit details
  2. Merge pull request #43 from vdemedes/add-stable-node

    Add stable node to .travis.yml
    sindresorhus committed Oct 22, 2015
    Copy the full SHA
    c5bb9a4 View commit details
  3. Close #42 PR: Shareable configs.

    vdemedes authored and sindresorhus committed Oct 22, 2015
    Copy the full SHA
    f1f1ceb View commit details

Commits on Oct 23, 2015

  1. bump deps

    sindresorhus committed Oct 23, 2015
    Copy the full SHA
    d52028f View commit details
  2. Copy the full SHA
    403916b View commit details
  3. eslint@1.7.3

    sindresorhus committed Oct 23, 2015
    Copy the full SHA
    360d373 View commit details
  4. add --fix flag

    sindresorhus committed Oct 23, 2015
    Copy the full SHA
    51cd3e1 View commit details
  5. remove moot catch handlers

    `meow` handles this for us
    sindresorhus committed Oct 23, 2015
    Copy the full SHA
    374a249 View commit details
  6. Copy the full SHA
    0b84f65 View commit details
  7. Copy the full SHA
    1c5e88d View commit details
  8. Copy the full SHA
    6f9fcb2 View commit details
  9. readme tweaks

    sindresorhus committed Oct 23, 2015
    Copy the full SHA
    39f7b36 View commit details
  10. Copy the full SHA
    bad12d7 View commit details
  11. 0.10.0

    sindresorhus committed Oct 23, 2015
    Copy the full SHA
    7644b9d View commit details

Commits on Oct 26, 2015

  1. Update readme.md

    sindresorhus committed Oct 26, 2015
    Copy the full SHA
    5d23bf1 View commit details
Showing with 4,565 additions and 648 deletions.
  1. +1 −4 .editorconfig
  2. +1 −1 .gitattributes
  3. +26 −0 .github/workflows/main.yml
  4. +5 −0 .gitignore
  5. +1 −0 .npmrc
  6. +0 −5 .travis.yml
  7. +204 −62 cli.js
  8. +73 −0 code-of-conduct.md
  9. +5 −0 config/overrides.cjs
  10. +368 −0 config/plugins.cjs
  11. +41 −0 contributing.md
  12. +155 −102 index.js
  13. +153 −0 lib/constants.js
  14. +45 −0 lib/open-report.js
  15. +616 −0 lib/options-manager.js
  16. +5 −17 license
  17. +300 −289 media/logo.ai
  18. +1 −1 media/logo.svg
  19. +133 −66 package.json
  20. +358 −90 readme.md
  21. +0 −11 test.js
  22. +191 −0 test/cli.js
  23. +3 −0 test/fixtures/config-files/xo-config/.xo-config
  24. +5 −0 test/fixtures/config-files/xo-config/file.js
  25. +3 −0 test/fixtures/config-files/xo-config_cjs/.xo-config.cjs
  26. +5 −0 test/fixtures/config-files/xo-config_cjs/file.js
  27. +3 −0 test/fixtures/config-files/xo-config_js/.xo-config.js
  28. +5 −0 test/fixtures/config-files/xo-config_js/file.js
  29. +3 −0 test/fixtures/config-files/xo-config_json/.xo-config.json
  30. +5 −0 test/fixtures/config-files/xo-config_json/file.js
  31. +5 −0 test/fixtures/config-files/xo_config_cjs/file.js
  32. +3 −0 test/fixtures/config-files/xo_config_cjs/xo.config.cjs
  33. +5 −0 test/fixtures/config-files/xo_config_js/file.js
  34. +3 −0 test/fixtures/config-files/xo_config_js/xo.config.js
  35. +3 −0 test/fixtures/custom-extension/one-space.unknown
  36. +1 −0 test/fixtures/custom-extension/readme.md
  37. +1 −0 test/fixtures/cwd/unicorn.js
  38. +5 −0 test/fixtures/default-options/package.json
  39. +15 −0 test/fixtures/engines-overrides/package.json
  40. +7 −0 test/fixtures/engines-overrides/promise-then-transpile.js
  41. +7 −0 test/fixtures/engines-overrides/promise-then.js
  42. +7 −0 test/fixtures/engines/package.json
  43. +1 −0 test/fixtures/eslintignore/.eslintignore
  44. +1 −0 test/fixtures/eslintignore/bar.js
  45. +1 −0 test/fixtures/eslintignore/foo.js
  46. +6 −0 test/fixtures/extends.js
  47. +1 −0 test/fixtures/gitignore-multiple-negation/!!!unicorn.js
  48. +1 −0 test/fixtures/gitignore-multiple-negation/!!unicorn.js
  49. +1 −0 test/fixtures/gitignore-multiple-negation/!unicorn.js
  50. +3 −0 test/fixtures/gitignore-multiple-negation/.gitignore
  51. +1 −0 test/fixtures/gitignore-multiple-negation/unicorn.js
  52. +5 −0 test/fixtures/gitignore/index.js
  53. +2 −0 test/fixtures/gitignore/test/.gitignore
  54. +6 −0 test/fixtures/gitignore/test/bar.js
  55. +6 −0 test/fixtures/gitignore/test/foo.js
  56. +9 −0 test/fixtures/ignores/dist/linter-error.js
  57. +5 −0 test/fixtures/ignores/index.js
  58. +13 −0 test/fixtures/ignores/package.json
  59. +2 −0 test/fixtures/negative-gitignore/.gitignore
  60. +1 −0 test/fixtures/negative-gitignore/bar.js
  61. +1 −0 test/fixtures/negative-gitignore/foo.js
  62. +3 −0 test/fixtures/nested-configs/child-override/.prettierrc
  63. +10 −0 test/fixtures/nested-configs/child-override/child-prettier-override/package.json
  64. +1 −0 test/fixtures/nested-configs/child-override/child-prettier-override/semicolon.js
  65. +10 −0 test/fixtures/nested-configs/child-override/package.json
  66. +3 −0 test/fixtures/nested-configs/child-override/two-spaces.js
  67. +5 −0 test/fixtures/nested-configs/child/package.json
  68. +1 −0 test/fixtures/nested-configs/child/semicolon.js
  69. +1 −0 test/fixtures/nested-configs/no-semicolon.js
  70. +5 −0 test/fixtures/nested-configs/package.json
  71. +3 −0 test/fixtures/nested/child-empty/package.json
  72. +1 −0 test/fixtures/nested/child-ignore/package.json
  73. +5 −0 test/fixtures/nested/child/package.json
  74. +2 −0 test/fixtures/nested/file.js
  75. +5 −0 test/fixtures/nested/package.json
  76. +1 −0 test/fixtures/nodir/nested/index.js
  77. +1 −0 test/fixtures/nodir/noextension
  78. +1 −0 test/fixtures/open-report/errors/one.js
  79. +1 −0 test/fixtures/open-report/errors/three.js
  80. +2 −0 test/fixtures/open-report/errors/two-with-warnings.js
  81. +1 −0 test/fixtures/open-report/successes/success.js
  82. +1 −0 test/fixtures/open-report/warnings/one.js
  83. +3 −0 test/fixtures/open-report/warnings/three.js
  84. +5 −0 test/fixtures/overrides/index.js
  85. +22 −0 test/fixtures/overrides/package.json
  86. +6 −0 test/fixtures/overrides/test/bar.js
  87. +6 −0 test/fixtures/overrides/test/foo.js
  88. +3 −0 test/fixtures/package.json
  89. +11 −0 test/fixtures/prettier/package.json
  90. +2 −0 test/fixtures/project/file.js
  91. +5 −0 test/fixtures/project/node_modules/eslint-config-custom/config.json
  92. +4 −0 test/fixtures/project/node_modules/eslint-config-custom/package.json
  93. +5 −0 test/fixtures/project/package.json
  94. +3 −0 test/fixtures/space/one-space.js
  95. +3 −0 test/fixtures/space/two-spaces.js
  96. +1 −0 test/fixtures/typescript/child/extra-semicolon.ts
  97. +1 −0 test/fixtures/typescript/child/no-semicolon.ts
  98. +5 −0 test/fixtures/typescript/child/package.json
  99. +3 −0 test/fixtures/typescript/child/sub-child/four-spaces.ts
  100. +5 −0 test/fixtures/typescript/child/sub-child/package.json
  101. +6 −0 test/fixtures/typescript/child/tsconfig.json
  102. +5 −0 test/fixtures/typescript/package.json
  103. +3 −0 test/fixtures/typescript/two-spaces.tsx
  104. +2 −0 test/fixtures/webpack/no-config/file1.js
  105. +2 −0 test/fixtures/webpack/no-config/file2.js
  106. +1 −0 test/fixtures/webpack/no-config/file3.js
  107. +2 −0 test/fixtures/webpack/with-config/file1.js
  108. +2 −0 test/fixtures/webpack/with-config/file2.js
  109. +9 −0 test/fixtures/webpack/with-config/webpack.config.js
  110. +307 −0 test/lint-files.js
  111. +333 −0 test/lint-text.js
  112. +96 −0 test/open-report.js
  113. +770 −0 test/options-manager.js
  114. +28 −0 test/print-config.js
  115. +1 −0 test/temp/.gitignore
5 changes: 1 addition & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -7,9 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
* text=auto
* text=auto eol=lf
*.ai binary
26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
- uses: codecov/codecov-action@v1
if: matrix.node-version == 14
with:
fail_ci_if_error: true
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
node_modules
yarn.lock
!test/fixtures/project/node_modules
test/fixtures/project/node_modules/.cache
.nyc_output
coverage
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

266 changes: 204 additions & 62 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,222 @@
#!/usr/bin/env node
'use strict';
var updateNotifier = require('update-notifier');
var getStdin = require('get-stdin');
var meow = require('meow');
var xo = require('./');

var cli = meow({
help: [
'Usage',
' $ xo [<file|glob> ...]',
'',
'Options',
' --init Add XO to your project',
' --compact Compact output',
' --stdin Validate code from stdin',
' --esnext Enable ES2015 support and rules',
' --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',
'',
'Examples',
' $ xo',
' $ xo index.js',
' $ xo *.js !foo.js',
' $ xo --esnext --space',
' $ xo --esnext --env=node --env=mocha',
'',
'Tips',
' Put options in package.json instead of using flags so other tools can read it.'
]
}, {
string: [
'_'
],
boolean: [
'init',
'compact',
'stdin'
]
import getStdin from 'get-stdin';
import meow from 'meow';
import formatterPretty from 'eslint-formatter-pretty';
import semver from 'semver';
import openReport from './lib/open-report.js';
import xo from './index.js';

const cli = meow(`
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 effective ESLint config 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.
`, {
importMeta: import.meta,
autoVersion: false,
booleanDefault: undefined,
flags: {
fix: {
type: 'boolean',
},
reporter: {
type: 'string',
},
env: {
type: 'string',
isMultiple: true,
},
global: {
type: 'string',
isMultiple: true,
},
ignore: {
type: 'string',
isMultiple: true,
},
space: {
type: 'string',
},
semicolon: {
type: 'boolean',
},
prettier: {
type: 'boolean',
},
nodeVersion: {
type: 'string',
},
plugin: {
type: 'string',
isMultiple: true,
},
extend: {
type: 'string',
isMultiple: true,
},
open: {
type: 'boolean',
},
quiet: {
type: 'boolean',
},
extension: {
type: 'string',
isMultiple: true,
},
cwd: {
type: 'string',
},
printConfig: {
type: 'string',
},
stdin: {
type: 'boolean',
},
stdinFilename: {
type: 'string',
},
},
});

updateNotifier({pkg: cli.pkg}).notify();
const {input, flags: options, showVersion} = cli;

var input = cli.input;
var opts = cli.flags;
// TODO: Fix this properly instead of the below workaround.
// Revert behavior of meow >8 to pre-8 (7.1.1) for flags using `isMultiple: true`.
// Otherwise, options defined in package.json can't be merged by lib/options-manager.js `mergeOptions()`.
for (const key in options) {
if (Array.isArray(options[key]) && options[key].length === 0) {
delete options[key];
}
}

function log(report) {
process.stdout.write(xo.getFormatter(opts.compact && 'compact')(report.results));
process.exit(report.errorCount === 0 ? 0 : 1);
// Make data types for `options.space` match those of the API
// Check for string type because `xo --no-space` sets `options.space` to `false`
if (typeof options.space === 'string') {
if (/^\d+$/u.test(options.space)) {
options.space = Number.parseInt(options.space, 10);
} else if (options.space === 'true') {
options.space = true;
} else if (options.space === 'false') {
options.space = false;
} else {
if (options.space !== '') {
// Assume `options.space` was set to a filename when run as `xo --space file.js`
input.push(options.space);
}

options.space = true;
}
}

if (opts.init) {
require('xo-init')();
return;
if (process.env.GITHUB_ACTIONS && !options.fix && !options.reporter) {
options.quiet = true;
}

const log = async report => {
const reporter = options.reporter || process.env.GITHUB_ACTIONS ? await xo.getFormatter(options.reporter || 'compact') : formatterPretty;
process.stdout.write(reporter(report.results));
process.exitCode = report.errorCount === 0 ? 0 : 1;
};

// `xo -` => `xo --stdin`
if (input[0] === '-') {
opts.stdin = true;
options.stdin = true;
input.shift();
}

if (opts.stdin) {
getStdin(function (str) {
log(xo.lintText(str));
});

return;
if (options.version) {
showVersion();
}

xo.lintFiles(input, opts, function (err, report) {
if (err) {
throw err;
if (options.nodeVersion) {
if (options.nodeVersion === 'false') {
options.nodeVersion = false;
} else if (!semver.validRange(options.nodeVersion)) {
console.error('The `--node-engine` flag must be a valid semver range (for example `>=6`)');
process.exit(1);
}
}

log(report);
});
(async () => {
if (options.printConfig) {
if (input.length > 0) {
console.error('The `--print-config` flag must be used with exactly one filename');
process.exit(1);
}

if (options.stdin) {
console.error('The `--print-config` flag is not supported on stdin');
process.exit(1);
}

options.filePath = options.printConfig;
const config = await xo.getConfig(options);
console.log(JSON.stringify(config, undefined, '\t'));
} else if (options.stdin) {
const stdin = await getStdin();

if (options.stdinFilename) {
options.filePath = options.stdinFilename;
}

if (options.fix) {
const {results: [result]} = await xo.lintText(stdin, options);
// If there is no output, pass the stdin back out
process.stdout.write((result && result.output) || stdin);
return;
}

if (options.open) {
console.error('The `--open` flag is not supported on stdin');
process.exit(1);
}

await log(await xo.lintText(stdin, options));
} else {
const report = await xo.lintFiles(input, options);

if (options.fix) {
await xo.outputFixes(report);
}

if (options.open) {
openReport(report);
}

await log(report);
}
})();
Loading