Skip to content

Conversation

@dersimn
Copy link
Contributor

@dersimn dersimn commented Feb 18, 2021

Reproduce

https://github.com/dersimn/issue-xo

package.json:

{
  "devDependencies": {
    "xo": "^0.36.1"
  },
  "xo": {
    "space": 4,
    "globals": [
      "myGlobalFunction"
    ]
  }
}

index.js:

function something(foo) {
    myGlobalFunction(foo);
}

something();
  1. npx xo
    • Runs without errors
  2. cat index.js | npx xo --stdin:
    • Returns: ✖ 2:5 myGlobalFunction is not defined. no-undef
    • However the space: 4 option is respected.
    • cat index.js | npx xo --globals myGlobalFunction --stdin works
    • Maybe because rules are simply forwarded to eslint and all other options are parsed by XO ?

This issue occurred first on update from v0.34.2 to v0.35.0.

Fix

The issue seems to be the update from "meow": "^7.1.1" to "meow": "^8.0.0".

To verify place console.log('foo', options); before line 61 in index.js and call cat index.js | npx xo --stdin:

With xo v0.34.2 (using meow v7.1.1) this debug line outputs:

foo { stdin: true }

With xo v0.35.0 (using meow v8.0.0) this debug line outputs:

foo {
  stdin: true,
  env: [],
  global: [],
  ignore: [],
  plugin: [],
  extend: [],
  extension: []
}

This is because the behavior of meow's isMultiple (used for e.g. here) changed when fixing sindresorhus/meow#161, however XO can't deal with this yet when merging CLI options with options from package.json.

Trace of calls:

Fixes:

Fixes #509
Fixes xojs/SublimeLinter-contrib-xo#17

@codecov-io
Copy link

Codecov Report

Merging #520 (9a666ed) into main (8156d42) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #520      +/-   ##
==========================================
+ Coverage   97.10%   97.12%   +0.02%     
==========================================
  Files           7        7              
  Lines         380      383       +3     
==========================================
+ Hits          369      372       +3     
  Misses         11       11              
Impacted Files Coverage Δ
cli-main.js 89.83% <100.00%> (+0.54%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8156d42...9a666ed. Read the comment docs.

@sindresorhus sindresorhus changed the title fix ignored package.json when using cli #509 Fix ignored package.json config when using the CLI Feb 20, 2021
@sindresorhus sindresorhus merged commit 32bd3b8 into xojs:main Feb 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Behaviour of xo --stdin and options defined in package.json xo config globals in package.json are ignored

3 participants