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

Add editorconfig #1102

Merged
merged 1 commit into from
Dec 14, 2016
Merged

Add editorconfig #1102

merged 1 commit into from
Dec 14, 2016

Conversation

SimenB
Copy link
Contributor

@SimenB SimenB commented Oct 2, 2016

It silences IntelliJ a least 😄
I think this should match the style in the repo.

image

@ljharb
Copy link
Collaborator

ljharb commented Oct 3, 2016

I don't think it's a good idea to include this file unless we can validate it against our existing code. Do you know of a tool that can do that?

@SimenB
Copy link
Contributor Author

SimenB commented Oct 3, 2016

Well, there is https://github.com/jedmao/eclint. I'm unable to make it work properly, though, and it seems unmaintained...

But the files use 2 space indent, trailing newline, and no trailing spaces.

All of these are validated by eslint already (maybe not utf-8, but that's usually default in modern editors, and I doubt this repo uses anything other than ascii either way), this file just automatically sets the IDE/text editor to those same settings.

@Vadorequest
Copy link

This may be what you need, I haven't looked deeply into it but it seems good.

https://github.com/sun1x/eslint-to-editorconfig

@SimenB
Copy link
Contributor Author

SimenB commented Oct 17, 2016

@Vadorequest so the test would be to run the tool, and expect git status to be clean?

@Vadorequest
Copy link

I think I misunderstood what you wanted, I was looking for a tool to generate a .editorconfig based on ESLint.

But yeah, you could generate the file using this module and match it against yours.

Copy link
Collaborator

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

(reiterating using the PR reviews feature) this is great, but it needs to come with a way to enforce its correctness in CI, or else it will drift.

@SimenB
Copy link
Contributor Author

SimenB commented Dec 7, 2016

@ljharb Found a tool to run a check on CI (same that webpack uses)

Copy link
Collaborator

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Awesome, this is looking great!

max_line_length = null

[*.md]
trim_trailing_whitespace = false
Copy link
Collaborator

Choose a reason for hiding this comment

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

why would we not want to trim trailing whitespace on markdown files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MD has significant whitespace, so if you want e.g. a linebreak without starting a new paragraph, you add two trailing spaces.

image

Want me to remove it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting, I was not aware of that.

It's fine to leave as-is then.

@@ -4,6 +4,7 @@
"description": "Airbnb's base JS ESLint config, following our styleguide",
"main": "index.js",
"scripts": {
"prelint": "editorconfig-tools check *.js rules/*.js test/*.js",
Copy link
Collaborator

Choose a reason for hiding this comment

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

huh, i wasn't aware you could "pre" any old script. Seems this works all the way back to npm 1.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This should probably cover jsx files too.

@@ -0,0 +1,14 @@
root = true

[*]
Copy link
Collaborator

Choose a reason for hiding this comment

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

if this is *, then the editorconfig check should also use * - if it's just js/jsx, then i'd like both places to match.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's a good point

@SimenB
Copy link
Contributor Author

SimenB commented Dec 7, 2016

Changed to run against every file

Copy link
Collaborator

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Will the commands in the sub packages work with a top-level editorconfig?

Would it be better to symlink the top-level config down to the individual folders, so they're included in a publish as well as being more discoverable?

@SimenB
Copy link
Contributor Author

SimenB commented Dec 7, 2016

Yes, it walks up the tree. I know it worked because it gave me failures on too long lines before I disabled that rule

@SimenB
Copy link
Contributor Author

SimenB commented Dec 7, 2016

I don't think the file needs to be included in a publish, it's just useful for contributors, having their IDE configured automatically

@ljharb
Copy link
Collaborator

ljharb commented Dec 7, 2016

@SimenB npm explore foo && npm install && npm test should work for every package - it definitely has to be included in the publish.

@SimenB
Copy link
Contributor Author

SimenB commented Dec 7, 2016

hm, ok. add a symbolic link, duplicate it, or copy it over during pubilsh (and gitignore it)?

@ljharb
Copy link
Collaborator

ljharb commented Dec 7, 2016

I think the symlink is probably the simplest solution.

@SimenB
Copy link
Contributor Author

SimenB commented Dec 7, 2016

Ok, symlinks pushed

Copy link
Collaborator

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Thanks! This LGTM pending a rebase.

@SimenB
Copy link
Contributor Author

SimenB commented Dec 14, 2016

@ljharb rebased

@ljharb
Copy link
Collaborator

ljharb commented Dec 14, 2016

hmm - when i try this locally, even if i add a hard tab, it doesn't error out.

@SimenB
Copy link
Contributor Author

SimenB commented Dec 14, 2016

Hmm, it doesn't seem to be able to check indent style... In the source code (https://github.com/slang800/editorconfig-tools/tree/master/lib/rules) it's called indent-char, but changing to that doesn't help.

It does correctly yell at me for trailing spaces, trailing newline, CRLF and size of indentation, though. And it also yelled at me for line length, but as it\s unable to ignore long strings or comments, it gave a lot of false positives.

A bummer it doesn't seems to check type of indent, but extra indent gets yelled at

@SimenB
Copy link
Contributor Author

SimenB commented Dec 14, 2016

Also, setting indent-style=tab makes it fail for spaces, so it just doesn't seem able to detect a single tab in all the spaces

@ljharb
Copy link
Collaborator

ljharb commented Dec 14, 2016

gotcha - seems i just got lucky and picked the one thing it can't detect. oh well, this seems fine :-)

@ljharb ljharb merged commit c30adcc into airbnb:master Dec 14, 2016
@SimenB
Copy link
Contributor Author

SimenB commented Dec 14, 2016

Hmm, If I set all indentation to tabs, it yells at me for not using spaces... Seems like a bug

@SimenB SimenB deleted the editorconfig branch December 14, 2016 08:25
@ljharb
Copy link
Collaborator

ljharb commented Dec 14, 2016

@SimenB please file that upstream if you don't mind ;-)

@SimenB
Copy link
Contributor Author

SimenB commented Dec 14, 2016

Done, notslang/editorconfig-tools#36

Thanks for merging!

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

Successfully merging this pull request may close these issues.

3 participants