flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
164.85k stars 27.16k forks source link

The project MUST automatically enforce its selected coding style(s) #123455

Open godofredoc opened 1 year ago

godofredoc commented 1 year ago

The project MUST automatically enforce its selected coding style(s) if there is at least one FLOSS tool that can do so in the selected language(s).

This MAY be implemented using static analysis tool(s) and/or by forcing the code through code reformatters. In many cases the tool configuration is included in the project's repository (since different projects may choose different configurations). Projects MAY allow style exceptions (and typically will); where exceptions occur, they MUST be rare and documented in the code at their locations, so that these exceptions can be reviewed and so that tools can automatically handle them in the future. Examples of such tools include ESLint (JavaScript), Rubocop (Ruby), and devtools check (R). Coding standards enforced justification

godofredoc commented 1 year ago

Engine

@zanderso @jmagman is this accurate? what about objc?

godofredoc commented 1 year ago

Flutter

godofredoc commented 1 year ago

@stuartmorgan is there a build in packages that enforces the code styles?

jmagman commented 1 year ago
  • x-clang-tidy enforce code style for c/c++ and python.

is this accurate? what about objc?

Mac Host clang-tidy and Mac iOS clang-tidy enforces code styles for Objective-C/Objective-C++.

https://github.com/flutter/engine/blob/8b3966c1f47ecf5190a614b83a26e7bdf558e7b7/.clang-tidy#L10

zanderso commented 1 year ago

I'm having a lot of trouble making sense of this issue, and as written I don't think it makes sense. It is conflating syntactic style checking (e.g. where whitespace is/isn't allowed to go) with semantic "style" checking. Calling semantic checks "style" checks is not correct, in my opinion. Instead, we'd typically call those checks "linting" or "static analysis" depending on the specifics of how they're implemented and what sorts of things they're looking for.

So, instead of trying to make sense of this issue as stated, I'll just give my summary of what we're doing. Feel free to ask follow up questions if you need more details.

In the flutter/engine repo:

In the flutter/flutter repo:

godofredoc commented 1 year ago

Thanks for the information, I'll copy it to the wiki.

The bug description is a copy/paste from the best practices, mainly for tracking purposes of what is being updated for flutter. I'll share the feedback with the OSSF team working on best practices.

Hixie commented 1 year ago

yeah we already do this in spades everywhere we can

stuartmorgan commented 1 year ago

@stuartmorgan is there a build in packages that enforces the code styles?

Dart, C++, C, Java, and Objective-C are all enforced by CI in flutter/packages. We don't yet have Swift (https://github.com/flutter/flutter/issues/41129) or Kotlin (https://github.com/flutter/flutter/issues/41129) (the latter we have close to zero non-flutter create-generated code of right now though as the policy is not to use it for plugins yet).