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

Update: addresses #9947 #10653

Closed
wants to merge 1 commit into from
Closed

Update: addresses #9947 #10653

wants to merge 1 commit into from

Conversation

mbildner
Copy link

@mbildner mbildner commented Jul 23, 2018

Format newly generated .eslintrc.js file before it is saved.

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

[x] Other, please explain:

Slight improvement in the cli by addressing #9947

What changes did you make? (Give an overview)

When a user creates a new .eslintrc.js file via eslint --init, the resulting file conforms to the rules generated by the cli.

Is there anything you'd like reviewers to focus on?

I could not figure out how to feature test this.

It is tested by implication: a unit test confirms that when a config file is written, if that file is a .js config file, and rules exist in the config that is being saved, then those rules are obeyed in the resulting file.

Also note: this change uses the Linter class under the hood instead of the CLIEngine. The latter cannot be imported by the ConfigFile class. I tried a little and decided it made more sense to reach straight to the Linter instead.

Format newly generated .eslintrc.js file before it is saved.
@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Jul 23, 2018
Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

For the test, one idea would be to use the mock-fs package, which is also used in a few other tests elsewhere.

@@ -18,7 +18,8 @@ const fs = require("fs"),
pathIsInside = require("path-is-inside"),
stripComments = require("strip-json-comments"),
stringify = require("json-stable-stringify-without-jsonify"),
requireUncached = require("require-uncached");
requireUncached = require("require-uncached"),
Linter = require("../linter.js");
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure using Linter here will work correctly when the generated config contains something like extends (i.e. when the user says they want to follow a popular styleguide). The second argument of Linter#verifyAndFix is supposed to be a "fully-resolved" config (i.e. it just has rules, without depending on any external plugins or extends clauses).

It might be better to use the CLIEngine#executeOnText API instead. For example, maybe something like this would work:

const results = new CLIEngine({ useEslintrc: false, ignore: false, baseConfig: config, fix: true })
    .executeOnText(content, ".eslintrc.js")

// ... extract output from results

@platinumazure platinumazure added enhancement This change enhances an existing feature of ESLint cli Relates to ESLint's command-line interface 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 Jul 23, 2018
@kaicataldo
Copy link
Member

@mbildner Friendly ping! Anything we can do to help you land this?

@nzakas
Copy link
Member

nzakas commented Dec 7, 2018

Closing, as there has been no activity 90 days.

@nzakas nzakas closed this Dec 7, 2018
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jun 6, 2019
@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 Jun 6, 2019
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 cli Relates to ESLint's command-line interface enhancement This change enhances an existing feature of ESLint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants