Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--print-config outputs empty config if called not from config file directory #6329

Closed
vsemozhetbyt opened this issue Jun 6, 2016 · 13 comments
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features

Comments

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Jun 6, 2016

What version of ESLint are you using?

2.11.1

What parser (default, Babel-ESLint, etc.) are you using?

default

Please show your full configuration:

e:\DOC\prg\js\node\.eslintrc.json

{
  "root": true,

  "extends": [
    "eslint:recommended",
    "airbnb-base"
  ],

  "parserOptions": {
    "ecmaVersion": 7,
    "sourceType": "script"
  },

  "env": {
    "browser": false,
    "es6": true,
    "node": true
  },

  "rules": {
    "eqeqeq": "error",
    "no-console": "off",
    "no-extra-parens": ["error", "all"],
    "quotes": ["error", "single"],
    "spaced-comment": ["error", "always", { "exceptions": ["/", "*"] }],
    "strict": ["error", "global"]
  }
}

What did you do? Please include the actual source code causing the issue.

I have a simple test script in the subdirectory relative to the config directory:

e:\DOC\prg\js\node\-test\test.js:

'use strict';



console.log(1);

eslint output (to be sure eslint really uses all the rules frome the additional configs):

e:\DOC\prg\js\node\-test>eslint test.js

E:\DOC\prg\js\node\-test\test.js
  4:2  error  More than 2 blank lines not allowed  no-multiple-empty-lines

✖ 1 problem (1 error, 0 warnings)

I want to see all the config set via eslint --print-config test.js.

What did you expect to happen?

All the rules from .eslintrc.json + eslint:recommended + airbnb-base should be shown.

What actually happened? Please include the actual, raw output from ESLint.

The output is:

{
  "globals": {},
  "env": {},
  "rules": {},
  "parserOptions": {}
}

However, if I place test.js in the same directory with .eslintrc.json, the output is a big proper rule set.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Jun 6, 2016
@vsemozhetbyt vsemozhetbyt changed the title Empty config in the --print-config otput --print-config outputs empty config if called not from config file directory Jun 6, 2016
@vsemozhetbyt
Copy link
Contributor Author

vsemozhetbyt commented Jun 6, 2016

The test case may be simplified: call eslint --print-config . from the config file directory and from a subdirectory — the first output is the the real set, the second one is empty.

@vsemozhetbyt
Copy link
Contributor Author

Debug outputs from the config file directory:

1

Debug outputs from a subdirectory:

2

@platinumazure
Copy link
Member

I'm really confused about showing the linting messages when the issue seems to be about --print-config. Am I missing something?

  • Is this about --print-config specifically?
  • Do you believe the wrong configuration is being loaded/used for your use case?

@vsemozhetbyt
Copy link
Contributor Author

I've put the linting messages as a proving that without --print-config eslint uses all the triple rule set even being called frome a subdirectory. However, just adding --print-config to call from the same subdirectory somehow cleans rule set for printing.

@vsemozhetbyt
Copy link
Contributor Author

I've added a note before the linting message. Is it clear now? Sorry, my English is clumsy(

@ilyavolodin
Copy link
Member

ilyavolodin commented Jun 6, 2016

Verified. Interesting. I though --print-config was running after configuration resolution process. If that would be the case, this should be happening.

Test case:

Running eslint --print-config Makefile.js from eslint root directory results in:

{
  "globals": {
    "__dirname": false,
    "__filename": false,
    "arguments": false,
    "Buffer": false,
    "clearImmediate": false,
    "clearInterval": false,
    "clearTimeout": false,
    "console": false,
    "exports": true,
    "GLOBAL": false,
    "global": false,
    "Intl": false,
    "module": false,
    "process": false,
    "require": false,
    "root": false,
    "setImmediate": false,
    "setInterval": false,
    "setTimeout": false
  },
  "env": {
    "node": true
  },
  "rules": {
    "no-alert": "error",
    "no-array-constructor": "error",
    "no-bitwise": "off",
    "no-caller": "error",
    "no-case-declarations": "error",
    "no-catch-shadow": "off",
    "no-class-assign": "error",
    "no-cond-assign": "error",
    "no-confusing-arrow": "off",
    "no-console": "error",
    "no-const-assign": "error",
    "no-constant-condition": "error",
    "no-continue": "off",
    "no-control-regex": "error",
    "no-debugger": "error",
    "no-delete-var": "error",
    "no-div-regex": "off",
    "no-dupe-class-members": "error",
    "no-dupe-keys": "error",
    "no-dupe-args": "error",
    "no-duplicate-case": "error",
    "no-duplicate-imports": "off",
    "no-else-return": "off",
    "no-empty": "error",
    "no-empty-character-class": "error",
    "no-empty-function": "off",
    "no-empty-pattern": "error",
    "no-eq-null": "off",
    "no-eval": "error",
    "no-ex-assign": "error",
    "no-extend-native": "error",
    "no-extra-bind": "error",
    "no-extra-boolean-cast": "error",
    "no-extra-label": "off",
    "no-extra-parens": "off",
    "no-extra-semi": "error",
    "no-fallthrough": "error",
    "no-floating-decimal": "error",
    "no-func-assign": "error",
    "no-implicit-coercion": "off",
    "no-implicit-globals": "off",
    "no-implied-eval": "error",
    "no-inline-comments": "off",
    "no-inner-declarations": "error",
    "no-invalid-regexp": "error",
    "no-invalid-this": "error",
    "no-irregular-whitespace": "error",
    "no-iterator": "error",
    "no-label-var": "error",
    "no-labels": "error",
    "no-lone-blocks": "error",
    "no-lonely-if": "off",
    "no-loop-func": "error",
    "no-mixed-requires": "error",
    "no-mixed-spaces-and-tabs": [
      "error",
      false
    ],
    "linebreak-style": "off",
    "no-multi-spaces": "error",
    "no-multi-str": "error",
    "no-multiple-empty-lines": "off",
    "no-native-reassign": "error",
    "no-negated-condition": "off",
    "no-negated-in-lhs": "error",
    "no-nested-ternary": "error",
    "no-new": "error",
    "no-new-func": "error",
    "no-new-object": "error",
    "no-new-require": "error",
    "no-new-symbol": "error",
    "no-new-wrappers": "error",
    "no-obj-calls": "error",
    "no-octal": "error",
    "no-octal-escape": "error",
    "no-param-reassign": "off",
    "no-path-concat": "error",
    "no-plusplus": "off",
    "no-process-env": "off",
    "no-process-exit": "error",
    "no-proto": "error",
    "no-prototype-builtins": "off",
    "no-redeclare": "error",
    "no-regex-spaces": "error",
    "no-restricted-globals": "off",
    "no-restricted-imports": "off",
    "no-restricted-modules": "off",
    "no-restricted-syntax": "off",
    "no-return-assign": "error",
    "no-script-url": "error",
    "no-self-assign": "error",
    "no-self-compare": "off",
    "no-sequences": "error",
    "no-shadow": "error",
    "no-shadow-restricted-names": "error",
    "no-whitespace-before-property": "off",
    "no-spaced-func": "error",
    "no-sparse-arrays": "error",
    "no-sync": "off",
    "no-ternary": "off",
    "no-trailing-spaces": "error",
    "no-this-before-super": "error",
    "no-throw-literal": "off",
    "no-undef": "error",
    "no-undef-init": "error",
    "no-undefined": "error",
    "no-unexpected-multiline": "error",
    "no-underscore-dangle": [
      "error",
      {
        "allowAfterThis": true
      }
    ],
    "no-unmodified-loop-condition": "error",
    "no-unneeded-ternary": "off",
    "no-unreachable": "error",
    "no-unsafe-finally": "off",
    "no-unused-expressions": "error",
    "no-unused-labels": "error",
    "no-unused-vars": [
      "error",
      {
        "vars": "all",
        "args": "after-used"
      }
    ],
    "no-use-before-define": "error",
    "no-useless-call": "off",
    "no-useless-computed-key": "off",
    "no-useless-concat": "error",
    "no-useless-constructor": "off",
    "no-useless-escape": "off",
    "no-useless-rename": "off",
    "no-void": "off",
    "no-var": "off",
    "no-warning-comments": "off",
    "no-with": "error",
    "no-magic-numbers": "off",
    "array-bracket-spacing": "off",
    "array-callback-return": "error",
    "arrow-body-style": "off",
    "arrow-parens": "off",
    "arrow-spacing": "off",
    "accessor-pairs": "off",
    "block-scoped-var": "off",
    "block-spacing": "error",
    "brace-style": [
      "error",
      "1tbs"
    ],
    "callback-return": [
      "error",
      [
        "cb",
        "callback",
        "next"
      ]
    ],
    "camelcase": [
      "error",
      {
        "properties": "never"
      }
    ],
    "comma-dangle": "error",
    "comma-spacing": "error",
    "comma-style": [
      "error",
      "last"
    ],
    "complexity": [
      "off",
      11
    ],
    "computed-property-spacing": "off",
    "consistent-return": "error",
    "consistent-this": "off",
    "constructor-super": "error",
    "curly": [
      "error",
      "all"
    ],
    "default-case": "error",
    "dot-location": "off",
    "dot-notation": [
      "error",
      {
        "allowKeywords": true
      }
    ],
    "eol-last": "error",
    "eqeqeq": "error",
    "func-names": "off",
    "func-style": [
      "error",
      "declaration"
    ],
    "generator-star-spacing": "off",
    "global-require": "off",
    "guard-for-in": "error",
    "handle-callback-err": [
      "error",
      "err"
    ],
    "id-length": "off",
    "indent": [
      "error",
      4,
      {
        "SwitchCase": 1
      }
    ],
    "init-declarations": "off",
    "jsx-quotes": "off",
    "key-spacing": [
      "error",
      {
        "beforeColon": false,
        "afterColon": true
      }
    ],
    "keyword-spacing": "error",
    "lines-around-comment": [
      "error",
      {
        "beforeBlockComment": true,
        "afterBlockComment": false,
        "beforeLineComment": true,
        "afterLineComment": false
      }
    ],
    "max-depth": "off",
    "max-len": "off",
    "max-nested-callbacks": "off",
    "max-params": "off",
    "max-statements": "off",
    "max-statements-per-line": "off",
    "new-cap": "error",
    "new-parens": "error",
    "newline-after-var": "error",
    "newline-before-return": "off",
    "newline-per-chained-call": "off",
    "object-curly-spacing": [
      "off",
      "never"
    ],
    "object-property-newline": "off",
    "object-shorthand": "off",
    "one-var": "off",
    "one-var-declaration-per-line": "error",
    "operator-assignment": "off",
    "operator-linebreak": "off",
    "padded-blocks": "off",
    "prefer-arrow-callback": "off",
    "prefer-const": "off",
    "prefer-reflect": "off",
    "prefer-rest-params": "off",
    "prefer-spread": "off",
    "prefer-template": "off",
    "quote-props": [
      "error",
      "as-needed"
    ],
    "quotes": [
      "error",
      "double"
    ],
    "radix": "error",
    "id-match": "off",
    "id-blacklist": "off",
    "require-jsdoc": "error",
    "require-yield": "off",
    "semi": "error",
    "semi-spacing": [
      "error",
      {
        "before": false,
        "after": true
      }
    ],
    "sort-vars": "off",
    "sort-imports": "off",
    "space-before-blocks": "error",
    "space-before-function-paren": [
      "error",
      "never"
    ],
    "space-in-parens": "error",
    "space-infix-ops": "error",
    "space-unary-ops": [
      "error",
      {
        "words": true,
        "nonwords": false
      }
    ],
    "spaced-comment": [
      "error",
      "always",
      {
        "exceptions": [
          "-"
        ]
      }
    ],
    "strict": [
      "error",
      "global"
    ],
    "template-curly-spacing": "off",
    "unicode-bom": "off",
    "use-isnan": "error",
    "valid-jsdoc": [
      "error",
      {
        "prefer": {
          "return": "returns"
        }
      }
    ],
    "valid-typeof": "error",
    "vars-on-top": "off",
    "wrap-iife": "error",
    "wrap-regex": "off",
    "yield-star-spacing": "off",
    "yoda": [
      "error",
      "never"
    ]
  },
  "parserOptions": {
    "ecmaFeatures": {
      "globalReturn": true
    }
  },
  "ecmaFeatures": {},
  "extends": "./packages/eslint-config-eslint/default.yml",
  "root": true
}

Running eslint --print-config cli.js from Eslint's lib directory, results in:

{
  "globals": {},
  "env": {},
  "rules": {},
  "parserOptions": {}
}

@ilyavolodin ilyavolodin added bug ESLint is working incorrectly core Relates to ESLint's core APIs and features accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Jun 6, 2016
@alberto
Copy link
Member

alberto commented Jun 8, 2016

I am working on this

@nzakas
Copy link
Member

nzakas commented Jun 8, 2016

I'm a bit confused here - what are we saying is the bug?

I'm pretty sure --print-config requires that you pass a file and not a pattern, so eslint --print-config . won't work while eslint --print-config foo.js will.

@vsemozhetbyt
Copy link
Contributor Author

vsemozhetbyt commented Jun 8, 2016

Does . not mean 'current directory' for eslint? Whatever the case, you can replace . by any path — the bug is still here: calling from config file directory and calling from any subdirectory relative to config file directory have different outputs for the same path.

@platinumazure
Copy link
Member

platinumazure commented Jun 8, 2016

@nzakas I think the problem is if you have foo.js and subfolder/bar.js, --print-config simply doesn't work when you pass in subfolder/bar.js (or any path where the file is not in the same folder as the config file). See this comment for more details.

@alberto
Copy link
Member

alberto commented Jun 8, 2016

@nzakas Here is a failing test case using a file, running from lib:
../bin/eslint.js --print-config ./cli.js

@vsemozhetbyt
Copy link
Contributor Author

vsemozhetbyt commented Jun 8, 2016

@platinumazure the bug depends not on path and not on relation between path and config file, but from relation between CWD and config file. If you call eslint for subfolder/bar.js from the same folder with config file, it is OK.

@ilyavolodin
Copy link
Member

@nzakas That's what I assumed as well. However, that's not what is happening. eslint --print-config . is working in the case that you have .eslintrc in the current directory, which is strange and not what I expected. But the tests that I posted are done on the file, not on the pattern. So it seems that there might be two bugs here. First one, --print-config on a file in the subdirectory returns an empty object. Second one, --print-config seems to work on patterns, when it shouldn't.

@nzakas nzakas closed this as completed in 8ec89c8 Jun 15, 2016
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features
Projects
None yet
Development

No branches or pull requests

6 participants