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

Fix: Correct [object Object] output of error.data. #9561

Merged
merged 1 commit into from Nov 5, 2017
Merged

Fix: Correct [object Object] output of error.data. #9561

merged 1 commit into from Nov 5, 2017

Conversation

jrpool
Copy link
Contributor

@jrpool jrpool commented Nov 1, 2017

Stops error.data from being output as [object Object] when the data property
is an object, such as a rule’s options object.

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

Tell us about your environment

  • ESLint Version:
    4.10.0
  • Node Version:
    9.0.0
  • npm Version:
    5.5.1
    What parser (default, Babel-ESLint, etc.) are you using?
    default
    Please show your full configuration:
"use strict";

const path = require("path");
const rulesDirPlugin = require("eslint-plugin-rulesdir");

rulesDirPlugin.RULES_DIR = path.join(__dirname, "tools/internal-rules");

module.exports = {
    root: true,
    plugins: [
        "eslint-plugin",
        "node",
        "rulesdir"
    ],
    extends: [
        "./packages/eslint-config-eslint/default.yml",
        "plugin:node/recommended",
        "plugin:eslint-plugin/recommended"
    ],
    rules: {
        "eslint-plugin/consistent-output": "error",
        "eslint-plugin/no-deprecated-context-methods": "error",
        "eslint-plugin/prefer-output-null": "error",
        "eslint-plugin/prefer-placeholders": "error",
        "eslint-plugin/report-message-format": ["error", "[^a-z].*\\.$"],
        "eslint-plugin/test-case-property-ordering": "error",
        "eslint-plugin/test-case-shorthand-strings": "error",
        "rulesdir/multiline-comment-style": "error"
    }
};

What did you do? Please include the actual source code causing the issue.
In a test file in test/lib/rules, in an invalidity test, set the value of options to an array of 1 option, which contained a property whose name was not specified in the schema of the rule. For example, set line 398 of test/lib/rules/object-property-newline.js to:
options: [{ XallowMultiplePropertiesPerLineX: true }],
What did you expect to happen?
I expected an intelligible error message explaining what was wrong.
What actually happened? Please include the actual, raw output from ESLint.
I received an error message that did not sufficiently explain what was wrong, namely:
Value [object Object] should NOT have additional properties.

What changes did you make? (Give an overview)

  1. I modified config-validator to check for the type of error.data. If error.data has a type other than string and is not an array, I changed it to its JSON stringification.
  2. I modified the expected error messages of 2 config-validator tests to match the formats of error.data that arise from their JSON stringification.

Is there anything you'd like reviewers to focus on?
Would it be better to check for other types not yet in use, or to invert the check and check only for non-array objects, or to JSON stringify everything regardless of type?

@aladdin-add aladdin-add added bug ESLint is working incorrectly core Relates to ESLint's core APIs and features evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Nov 2, 2017
@mysticatea
Copy link
Member

Thank you for the contribution!

Looks great to me.
Personally, I think better if it JSON-stringify everything regardless of type.

@jrpool
Copy link
Contributor Author

jrpool commented Nov 3, 2017

Thank you for your comment, @mysticatea. I’ll be happy to make that change, unless anybody else disagrees.

@platinumazure
Copy link
Member

With the error.data no longer surrounded by quotation marks, I would also be okay with unconditional stringification. Thanks!

Stops error.data from being output as [object Object] when the data property
is an object, such as a rule’s options object, by JSON-stringifying error.data.
@jrpool
Copy link
Contributor Author

jrpool commented Nov 3, 2017

I have revised this PR to JSON-stringify error.data in all cases, as recommended by @mysticatea and @platinumazure.

@ilyavolodin ilyavolodin added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Nov 4, 2017
Copy link
Member

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@ilyavolodin ilyavolodin merged commit b7c5b19 into eslint:master Nov 5, 2017
@jrpool jrpool deleted the configval branch November 5, 2017 17:25
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators May 5, 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 May 5, 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

Successfully merging this pull request may close these issues.

None yet

5 participants