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

expiring-todo-comments breaks eslint --print-config in dirs with no package.json #373

Closed
garyking opened this issue Sep 16, 2019 · 7 comments · Fixed by #385
Closed

expiring-todo-comments breaks eslint --print-config in dirs with no package.json #373

garyking opened this issue Sep 16, 2019 · 7 comments · Fixed by #385

Comments

@garyking
Copy link
Contributor

If eslint --print-config is run in a dir with no package.json, then the expiring-todo-comments rule throws an error. So the --print-config command doesn't work with this rule, at the moment.

$ eslint --print-config src/index.js

Error: ENOENT: no such file or directory, open 'src/package.json'
Referenced from: .eslintrc.js
    at Object.openSync (fs.js:448:3)
    at Object.readFileSync (fs.js:350:35)
    at AsyncFunction.module.exports.sync (/usr/local/lib/node_modules/eslint-plugin-unicorn/node_modules/read-pkg/index.js:34:28)
    at Object.<anonymous> (/usr/local/lib/node_modules/eslint-plugin-unicorn/rules/expiring-todo-comments.js:20:21)
    at Module._compile (internal/modules/cjs/loader.js:936:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
    at Module.load (internal/modules/cjs/loader.js:790:32)
    at Function.Module._load (internal/modules/cjs/loader.js:703:12)
    at Module.require (internal/modules/cjs/loader.js:830:19)
    at require (internal/modules/cjs/helpers.js:68:18)
@MrHen MrHen changed the title eslint --print-config fails in dirs with no package.json expiring-todo-comments breaks eslint --print-config in dirs with no package.json Sep 16, 2019
@MrHen MrHen changed the title expiring-todo-comments breaks eslint --print-config in dirs with no package.json expiring-todo-comments breaks eslint --print-config in dirs with no package.json Sep 16, 2019
@MrHen
Copy link
Contributor

MrHen commented Sep 16, 2019

@lubien, you are probably most familiar with this rule. Any thoughts?

@lubien
Copy link
Contributor

lubien commented Sep 19, 2019

It might happen because one of my [conditions] on TODO rules reads a package.json

The solution would possibly try-catch for it, I can tackle this tomorrow if you're okay with it.

@MrHen
Copy link
Contributor

MrHen commented Sep 19, 2019

Awesome, thanks.

@lubien
Copy link
Contributor

lubien commented Sep 21, 2019

@garyking could you provide some steps to reproduce it?

Just did a fresh install of this rule and ran eslint --print-config src/index.js and it works ok.

eslint --print-config src/index.js
λ test-eslint eslint --print-config src/index.js
{
  "env": {
    "es6": true
  },
  "globals": {},
  "parser": null,
  "parserOptions": {
    "ecmaVersion": 2020,
    "sourceType": "module"
  },
  "plugins": [
    "unicorn"
  ],
  "rules": {
    "unicorn/catch-error-name": [
      "error"
    ],
    "unicorn/consistent-function-scoping": [
      "error"
    ],
    "unicorn/custom-error-definition": [
      "off"
    ],
    "unicorn/error-message": [
      "error"
    ],
    "unicorn/escape-case": [
      "error"
    ],
    "unicorn/expiring-todo-comments": [
      "error"
    ],
    "unicorn/explicit-length-check": [
      "error"
    ],
    "unicorn/filename-case": [
      "error"
    ],
    "unicorn/import-index": [
      "error"
    ],
    "unicorn/new-for-builtins": [
      "error"
    ],
    "unicorn/no-abusive-eslint-disable": [
      "error"
    ],
    "unicorn/no-array-instanceof": [
      "error"
    ],
    "unicorn/no-console-spaces": [
      "error"
    ],
    "unicorn/no-fn-reference-in-iterator": [
      "off"
    ],
    "unicorn/no-for-loop": [
      "error"
    ],
    "unicorn/no-hex-escape": [
      "error"
    ],
    "unicorn/no-keyword-prefix": [
      "off"
    ],
    "no-nested-ternary": [
      "off"
    ],
    "unicorn/no-nested-ternary": [
      "error"
    ],
    "unicorn/no-new-buffer": [
      "error"
    ],
    "unicorn/no-process-exit": [
      "error"
    ],
    "unicorn/no-unreadable-array-destructuring": [
      "error"
    ],
    "unicorn/no-unsafe-regex": [
      "off"
    ],
    "unicorn/no-unused-properties": [
      "off"
    ],
    "unicorn/no-zero-fractions": [
      "error"
    ],
    "unicorn/number-literal-case": [
      "error"
    ],
    "unicorn/prefer-add-event-listener": [
      "error"
    ],
    "unicorn/prefer-dataset": [
      "error"
    ],
    "unicorn/prefer-event-key": [
      "error"
    ],
    "unicorn/prefer-exponentiation-operator": [
      "error"
    ],
    "unicorn/prefer-flat-map": [
      "error"
    ],
    "unicorn/prefer-includes": [
      "error"
    ],
    "unicorn/prefer-node-append": [
      "error"
    ],
    "unicorn/prefer-node-remove": [
      "error"
    ],
    "unicorn/prefer-query-selector": [
      "error"
    ],
    "unicorn/prefer-reflect-apply": [
      "error"
    ],
    "unicorn/prefer-spread": [
      "error"
    ],
    "unicorn/prefer-starts-ends-with": [
      "error"
    ],
    "unicorn/prefer-text-content": [
      "error"
    ],
    "unicorn/prefer-type-error": [
      "error"
    ],
    "unicorn/prevent-abbreviations": [
      "error"
    ],
    "unicorn/regex-shorthand": [
      "error"
    ],
    "unicorn/throw-new-error": [
      "error"
    ]
  },
  "settings": {}
}

@garyking
Copy link
Contributor Author

Oh damn, it must be because I'm using eslint v5, rather than the latest v6. I can't upgrade that yet, unfortunately.

I'd appreciate it if you could fix this for eslint v5, since I and a lot of people are still using it, due to the major changes needed for some to upgrade to eslint v6. But I can understand if you won't fix the plugin just for eslint v5.

@garyking
Copy link
Contributor Author

Would one simple fix be to replace read-pkg with read-pkg-up?

@lubien
Copy link
Contributor

lubien commented Sep 22, 2019

Oh damn, it must be because I'm using eslint v5

I'm on it!

Would one simple fix be to replace read-pkg with read-pkg-up?

I'll check it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants