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

Gulp format not behaving as expected #26

Closed
bryceosterhaus opened this issue Dec 16, 2016 · 12 comments · Fixed by #47
Closed

Gulp format not behaving as expected #26

bryceosterhaus opened this issue Dec 16, 2016 · 12 comments · Fixed by #47
Labels

Comments

@bryceosterhaus
Copy link
Member

This commit metal/metal.js@b467094 is entirely from the gulp format task. There are some strange results from the formatter that we should figure out, specifically indentation issues. See metal/metal.js@b467094#diff-8613848b3fa31f88bb889f2483e95900R937 for reference

bryceosterhaus added a commit to bryceosterhaus/metal.js that referenced this issue Dec 16, 2016
bryceosterhaus added a commit to bryceosterhaus/metal.js that referenced this issue Dec 16, 2016
bryceosterhaus added a commit to bryceosterhaus/metal.js that referenced this issue Dec 16, 2016
@mairatma mairatma added the bug label Dec 16, 2016
bryceosterhaus added a commit to bryceosterhaus/metal.js that referenced this issue Dec 19, 2016
mairatma pushed a commit to metal/metal.js that referenced this issue Dec 19, 2016
@jbalsas
Copy link

jbalsas commented Jan 20, 2017

Might be worth to take a look into https://github.com/jlongster/prettier for this?

In technical terms: prettier parses your JavaScript into an AST and pretty-prints the AST, completely ignoring any of the original formatting. Say hello to completely consistent syntax!

@bryceosterhaus
Copy link
Member Author

@jbalsas, it looks promising. However, it is very very new so I would be hesitant to adopting something so quickly. I thought the discussion on this issue was very helpful though, prettier/prettier#40, especially when it comes to all sorts of Liferay formatting standards.

I do love the idea of having something that will auto-format in the editor though, it would be very useful and one less thing to worry about while coding.

@jbalsas
Copy link

jbalsas commented Jan 25, 2017

Hey @bryceosterhaus, reading through the updated Google JavaScript Style Guide I noticed this appendix in the 9.3 Style-related tools section. Seems like we could use ClangFormat for this.

It has:

@julien
Copy link

julien commented Jan 25, 2017

Hi @bryceosterhaus and @jbalsas,

I wanted to suggest ESLint to the possible options, it has a --fix option which can reformat the code too.

@eduardolundgren
Copy link
Contributor

eduardolundgren commented Feb 23, 2017

To summarize what we've been discussing our JavaScript projects must follow Google JavaScript Style Guide, and it can be enforced by the usage of the Google eslint config.

We can use prettier to auto-format the code based on Google rules (or at least as close as possible).

  gulp.task('format', () => gulp.src('src/**/*.js')
    .pipe(prettier({
      bracketSpacing: false,
      singleQuote: true,
      trailingComma: 'all',
    }))
    .pipe(gulp.dest('src')));

Everything seemed fine after formatting with prettier, there are few options on ESLint that need to be disabled.

{
  "extends": ["eslint:recommended", "google"],
  "parserOptions": {
      "ecmaVersion": 2017,
      "sourceType": "module"
  },
  "env": {
    "es6": true
  },
  "rules": {
    "arrow-parens": 0, // disabled because of prettier
    "comma-spacing": 0, // disabled because of prettier
    "no-console": 0,
    "no-process-env": 0
  }
}

There is one enforcement that prettier does that is incompatible with Google Style Guide, the usage of semi-colon. Seems like prettier will add support to it prettier/prettier#736. After that we are fine to go with this configuration.

Let me know if you guys are fine with this setup. Thank you!

/cc @fernandosouza @jbalsas Could you guys keep an eye on prettier support for semi-colon and once we have that we can migrate gulp-metal and all our projects to this configuration.

@fernandosouza
Copy link

Sure, @eduardolundgren. I'm following the issue and the repo as well.

@jbalsas
Copy link

jbalsas commented Feb 24, 2017

Hey @eduardolundgren, I'm not sure I understand the semicolon issue.

Google Style Guide states that:

Every statement must be terminated with a semicolon. Relying on automatic semicolon insertion is forbidden. [*]

[*] 4.3.2 Semicolons are required

Other than that, I'm pretty happy with this setup. Should we also try to enforce the usage of a Pre-commit hook?

@eduardolundgren
Copy link
Contributor

@jbalsas Yes, prettier doesn't require semicolons, in reality it removes the semicolon, that's why they will add an option for that.

@jbalsas
Copy link

jbalsas commented Mar 6, 2017

I actually think the rather enforce it very strictly... https://github.com/prettier/prettier/blob/b91d6384a6db769789ecd332cdf3b26e1e4d59c2/src/printer.js#L958-L959

See this gist

I understand the issue to be the opposite... people asking to be able to write without semicolons. Where did you see them being removed?

@eduardolundgren
Copy link
Contributor

eduardolundgren commented Mar 13, 2017

I would disable more roles:

{
  "extends": ["eslint:recommended", "google"],
  "parserOptions": {
      "ecmaVersion": 2017,
      "sourceType": "module"
  },
  "env": {
    "es6": true
  },
  "rules": {
    "arrow-parens": 0, // disabled because of prettier
    "comma-spacing": 0, // disabled because of prettier
    "no-empty": 0, // disable because we would like to allow empty blocks
    "no-console": 0,
    "no-process-env": 0
  }
}

@bryceosterhaus
Copy link
Member Author

Any updates with this? Prettier released v1.1 recently and it seems to work pretty well, I added it to both devtools and css-transitions using it through eslint-plugin-prettier.

@jbalsas
Copy link

jbalsas commented Apr 17, 2017

Hey @bryceosterhaus, I sent #47 a while ago. I need to update it now that 1.0 has been released and useTabs is available 😉

We also have a guidelines document we plan to present as soon as possible with this and other related guidelines.

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

Successfully merging a pull request may close this issue.

6 participants