editorconfig-core-js icon indicating copy to clipboard operation
editorconfig-core-js copied to clipboard

Add editorConfig properties to package.json?

Open kevinSuttle opened this issue 8 years ago • 40 comments

In the spirit of ESLint and Babel, would it make sense to allow editorConfig settings in package.json? I feel like it probably doesn't, but I wanted to have it documented either way to be definitive.

i.e.

"editorConfig" : {
}

Could also add presets: https://github.com/editorconfig/editorconfig-core-js/issues/31

kevinSuttle avatar Dec 08 '15 15:12 kevinSuttle

That's rather JavaScript specific, which isn't really in the design goals of EditorConfig.

jednano avatar Dec 11 '15 18:12 jednano

@jedmao No. It's not.

Look at how YAML does it. https://docs.cloudfoundry.org/devguide/deploy-apps/manifest.html#multi-manifests

kevinSuttle avatar Dec 11 '15 18:12 kevinSuttle

Ah, see, I didn't realize this was on the core-js repo. Seeing as it is, I have no problems with such a feature; though, we still need to look in subfolders for both .editorconfig and package.json files, which means the package.json file needs to define "root": true if that's the case. Then, what happens if you have both an .editorconfig as well as a package.json file in the same folder, both with an EditorConfig configuration? Which one takes precedent? I can see some issues to address here.

jednano avatar Dec 11 '15 19:12 jednano

Tools like eslint have this exact scenario. It's just a priority order. http://eslint.org/docs/user-guide/configuring#configuration-file-formats

http://eslint.org/docs/user-guide/configuring#extending-configuration-files

kevinSuttle avatar Dec 11 '15 19:12 kevinSuttle

Would prefer to see someone make some standard config file (or folder) for all configs to live in rather than continuing to clutter package.json with xyz.

...that said, if it does get in, I'll probably use it.

corysimmons avatar Feb 26 '16 04:02 corysimmons

Likewise, I will use this. @jedmao, what can we do to help? Do we need to look into the plugin and make a PR for the functionality? Could someone help with documentation? I’d love to see this get in on the next release.

jonathantneal avatar Feb 26 '16 15:02 jonathantneal

First, we need to come up with an acceptable spec. At first glance, I'm imagining something like the following:

{
  "editorConfig": {
    "root": true,
    "settings": [
      {
        "*": {
          "indent_style": "space",
          "indent_size": 4
        }
      },
      {
        "package.json": {
          "indent_size": 2
        }
      }
    ]
  }
}

It doesn't look as clean as the INI file format that .editorconfig uses, but this is the only way I could imagine supporting it in a package.json file.

BTW – you should theoretically be able to have any number of package.json files throughout your project. I would imagine that if both package.json and .editorconfig files were in a directory that the .editorconfig file would take precedence, but I'm open to discussion.

I took a look at the multilevel-ini and other INI parsing packages, but none of them account for ordered settings. I think the example structure I provided above is the only structure that would support this.

jednano avatar Feb 26 '16 18:02 jednano

Another alternative would be the following structure:

{
  "editorConfig": [
    ["root", true],
    ["*", {
      "indent_style": "space",
      "indent_size": 4
    }]
  ]
}

jednano avatar Feb 26 '16 18:02 jednano

@jedmao, thanks for the fast reply!

I’m a fan of the first syntax you’ve shared, and I would expect, as you’ve said, that the .editorconfig file takes precedent when both it and a package.json are present. Would this support an extends property being added alongside root and the other rules?

jonathantneal avatar Feb 26 '16 19:02 jonathantneal

@jonathantneal anything above existing functionality would be a separate ticket. Please open another issue for that feature request and detail how it might work.

BTW – I'm not at all suggesting I have any bandwidth to implement this package.json feature. I still have zero interest in the feature for my own use, so I won't be using it.

I would, however, consider merging in a PR, if it were implemented properly. That is, of course, the purpose of this discussion, to talk about what a proper implementation would be.

jednano avatar Feb 26 '16 21:02 jednano

@jonathantneal See https://github.com/editorconfig/editorconfig/issues/245

kevinSuttle avatar Feb 26 '16 21:02 kevinSuttle

Hey there. What can I do to help with moving this forward? Do we still need help defining the request more clearly? We have a year of sharable configs under our belt for most if-not-all linters. Does the configuration just need an outlined JSON version? Is this something we should be writing plugins for Atom / Sublime first for?

Example package.json with inline rules:

{
    "root": true,
    "rules": {
        "*": {
            "indent_style": "tab",
            "indent_size": "tab",
            "tab_width": "4",
            "end_of_line": "lf",
            "charset": "utf-8",
            "trim_trailing_whitespace": true,
            "insert_final_newline": true,
            "max_line_length": "off"
        }
    }
}

Example package.json extending a local editor-config-jonathantneal package:

{
    "root": true,
    "extends": "jonathantneal"
}

jonathantneal avatar Sep 16 '16 13:09 jonathantneal

+1

ButuzGOL avatar Dec 05 '16 13:12 ButuzGOL

I would love to contribute somehow on getting this thing moving! There's really no other way to re-use .editorconfig's across multiple repos.

andreiglingeanu avatar Apr 09 '17 08:04 andreiglingeanu

Nope. No other way. And remember, this is just for the js core. Other cores would need some kind of implementation too. I think we should stay focused on the OP's request and just support configuration in a package.json file for now and then start worrying about how the "extends" feature would work.

jednano avatar Apr 10 '17 02:04 jednano

@jedmao Every core has its own options parsing code duplicated? That is, .editorconfig is pretty much hardcoded in each of them, right?

andreiglingeanu avatar Apr 10 '17 06:04 andreiglingeanu

Yes, it has to be duplicated because the cores are written in different languages. The only thing that's not duplicated are the tests, which are shared across cores.

jednano avatar Apr 10 '17 13:04 jednano

Seems reasonable enough, thanks.

andreiglingeanu avatar Apr 10 '17 14:04 andreiglingeanu

I just did a pretty hefty rewrite of the source code into TypeScript. Anyone interested in taking this feature further? Been a bit of silence.

jednano avatar Oct 21 '17 01:10 jednano

I'd love to hop in to help a bit but I'm not really able to get the local dev setup working. The local bin/editorconfig definitely doesn't get created after doing npm install; npm link. Is that something easily fixable?

Other than that, the implementation for supporting editorConfig entry in package.json seems quite doable to me.

andreiglingeanu avatar Oct 23 '17 19:10 andreiglingeanu

@andreiglingeanu I think the issue you are experiencing is related to https://github.com/editorconfig/editorconfig-core-js/issues/55. Perhaps we should do it the other way and remove the ./bin folder from package.json and restore the ./bin/editorconfig.

jednano avatar Oct 23 '17 20:10 jednano

Hey @jedmao, yes, that it is. The bin/editorconfig file did not get generated at all in my local setup.

andreiglingeanu avatar Oct 24 '17 06:10 andreiglingeanu

@andreiglingeanu, aha! See #60. Now that the package.json file expects to be published in the ./dist folder, that's where the npm link command needs to be run. Make sense? Or npm link ./dist from the project root. Either way.

jednano avatar Oct 24 '17 23:10 jednano

We are good to go! Expect the pull request soon.

andreiglingeanu avatar Oct 25 '17 06:10 andreiglingeanu

Maybe I'm late to the party, but would this adhere to the cosmiconfig configuration file spec?

One of the main reasons to avoid a mandatory "root": true would be that it

Stops at the first configuration found, instead of finding all that can be found up the directory tree and merging them automatically.

Secondly, it would make it easier to adapt the other (defacto) standard to support different types of configuration files.

Thirdly, priority of configuration files can also be configured (and therefore predictable).

Would Editorconfig be open for other configuration file formats? Or would it be easier to open a separate issue to discuss that?

BtM909 avatar Feb 19 '18 23:02 BtM909

@BtM909 I was looking at package-json myself, but it looks like cosmiconfig has a bit more popularity. Not sure the delta between them.

As for other configuration file formats. What did you have in mind?

jednano avatar Feb 20 '18 06:02 jednano

Sorry, completely missed your update... My apologies!

As for other configuration file formats. What did you have in mind?

What formats are you specifically referring to? I was just references the fact that cosmiconfig supports multiple file formats by default, like:

  • a package.json property
  • a JSON or YAML, extensionless "rc file"
  • an "rc file" with the extensions .json, .yaml, .yml, or .js.
  • a .config.js CommonJS module

BtM909 avatar Jun 25 '18 13:06 BtM909

@andreiglingeanu - did you ever make the pull request for this? Thanks for your help.

mattgreenfield avatar Apr 23 '19 09:04 mattgreenfield

Is there any movement on this feature?

ColtHands avatar Sep 05 '20 21:09 ColtHands

bump

lucasvazq avatar Apr 03 '22 17:04 lucasvazq