Git Product home page Git Product logo

styleguide's Introduction

Goodbyte Styleguide

[ Usage ] [ Contributing ] [ Rational ]

The Styleguide is a set of formatting choices made to ensure our codebase is easy to read, easy to contribute to, and above all, consistent with itself. This style is defined and enforced by the linter configurations in this repository. These rules are not set in stone, and if you find that the linter is suggesting something you find less readable, please feel free to request a change to the rules (see: Contributing).

Usage

It is recommended that you install the ESLint, Stylelint, and Textlint plugins available for your IDE, and configure it to autoformat on save. For Visual Studio Code, you can find them in the extension marketplace: ESLint, Stylelint, Textlint; and you can enable auto-formatting by adding these settings to the repo’s .vscode/settings.json file.

Each linter configuration covers a different set of languages and file types. For languages that are covered by multiple linters, install all of them. There are currently three lint-configs:

Finally, it is recommended that you add this yaml file to the repo’s .github/workflows/ directory to add a lint check to every push and pull-request on the main branch.

ESLint

For Javascript and Vue projects (.js, .jsx, .vue). Install the npm package by running:

npm install eslint eslint-config-goodbyte-styleguide --save-dev
# or
pnpm add eslint-config-goodbyte-styleguide -D

Then, add it to the .eslintrc file at the root of the repo:

{
    "extends": "goodbyte-styleguide"
}

Stylelint

For CSS and Vue projects (.css, .vue). Install the npm package by running:

npm install stylelint stylelint-config-goodbyte-styleguide --save-dev
# or
pnpm add stylelint-config-goodbyte-styleguide -D

Then, add it to the .stylelintrc file at the root of the repo:

{
    "extends": "stylelint-config-goodbyte-styleguide"
}

Textlint

For Markdown (or any projects containing a README) (.md, .txt). Install the npm package by running:

npm install textlint textlint-rule-preset-goodbyte-styleguide --save-dev
# or
pnpm add textlint-rule-preset-goodbyte-styleguide -D

Then, add it to the .textlintrc file at the root of the repo:

{
	"rules": { "preset-goodbyte-styleguide": true }
}

Contributing

If you find a bug, a missing use-case, or wish to add an additional config, please feel encouraged to contribute. This styleguide is a living document, and nothing is set in stone. If you find that the linter is too strict, not strict enough, or otherwise lacking, open an issue (or pull-request if you know what the fix would be).

When updating the rules, note that each folder is published to npm separately. Packages will only be published if the version number in the package.json file is increased.

Rational

The following covers some FAQs about the rational behind this styleguide’s choices.

  1. Why use a linter at all?

    When combined with an auto-formatter, linters are a very powerful tool. Not only do they help keep the codebase consistent while reading, but they take a significant amount of the mental load off needing to think about formatting (although a linter without an auto-formatter increases this mental load). They catch small mistakes you’d regret missing, and reduce the need to ever fix the formatting of some other part of the codebase.

  2. "Styleguide"?

    We format styleguide as a single word (rather than "style-guide" or "style guide") because it is its own thing, deserving of its own word. This styleguide can be referred to as "the Styleguide" with an uppercase S, since it is a proper noun, but otherwise the word should be written like a common noun (lowercase).

  3. Tabs?

    "Tabs vs Spaces" is a common point of contention that many have agreed is rather pointless, concluding: "choose the one you like, it doesn’t really matter." We disagree.

    Indenting with spaces is stupid because it is overriding the computer’s built-in tab character and replacing it with something that might look like a tab character but is actually a bunch of spaces in a row. The result is that the size of the indentation (2 spaces, 4 spaces, etc.) is burned into the code, and therefore "more consistent" across environments. However, this is a misguided goal. Code does not need to be consistent across all environments, just all of your environments. I personally like my code indented at a width of 4, and when working with a codebase that uses spaces, must adjust to the (now inconsistent) use of 2 or 4 or 8 spaces of indentation instead. Burning this width into the code is as if the codebase shipped with its own required font. All of my environments look consistent because I have configured them to look consistent (colors, font, tab-width), and forcing everyone to use the same tab-width because you cannot figure out how to configure your environment is silly. The code must be consistent with itself, but need not look identical across different developers’ computers.

    By using tabs, everyone can set their own preferred tab-width, and the usage is simple: press the tab-key and get a tab character. Each level of indentation is one tab, and without the hackery of spaces pretending to be tabs, there is no such thing as a malformed tab-and-a-half.

  4. Why does CSS and JS have different curly-brace rules?

    They are different languages and have different syntax. As a result, the formatting that is most readable is not the same. Placing a newline character before the curly-brace ({) creates a space between the header of the block and the content of the block, as well as a direct line between the opening brace and the closing brace. While this aides readability, some languages (such as Go) strongly enforce same-line-braces instead. Despite allowing you to do either, Javascript has evolved as a language where same-line-braces are so ubiquitous that it has shaped the syntax. As a result, same-line-braces are often the most readable choice for Javascript, and the one we choose here.

styleguide's People

Contributors

qjack001 avatar

Watchers

 avatar

styleguide's Issues

CSS not indented in `<style>` block of Vue files

What it currently does

Currently, unindented CSS does not violate any rules. This is inconsistent with other rules that require code in the <script> and <template> blocks start a 1 level of indentation. Worse, it allows for inconsistent indentation within the block, allowing things like:

<style>
	body
{
		font-family: monospace;
		font-size: 14px;
		background: var(--background);
	}
</style>

and when --fix is run, "corrects" to:

<style>
body
	{
	font-family: monospace;
	font-size: 14px;
	background: var(--background);
}
</style>

What it should do

CSS should be indented starting at 1 indentation, and increase by 1 indentation every increase in depth. It should be consistent through out the <style> block.

<style>
	body
	{
		font-family: monospace;
		font-size: 14px;
		background: var(--background);
	}
</style>

Exception for CSS `top` property

What it currently does

The CSS property top is banned in favour of its "logical" replacement. However, the replacement property does not seem to have very widespread support. Further, it is not fulfilling its goal of being logical, as often the thing I am trying to achieve is "place this at the top" — not at the start of the document or whatever.

What it should do

Let me use top without having to disable stylelint.

Use `text-align: start` over `text-align: left`

What it currently does

No Stylelint warnings or errors on using text-align: left or right, or other left-to-right assuming rules in CSS.

What it should do

Error and fix to text-align: start or end to work with languages that read right-to-left. Can be comment-ignored if there is a valid need for left/right specificity.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.