Giter Site home page Giter Site logo

frontend-configs's Introduction

DEPRECATED

This repository is deprecated and superseded by https://github.com/avenga especially https://github.com/avenga/eslint-config. TSLint is not supported anymore and has equivalent ESLint configs in the new space. All other configs will become respective equivalents in the new space.

Sevenval Frontend Configs

This repository contains configuration files for several tools commonly used when developing frontends.

Table of contents:

Editorconfig

All popular editors support EditorConfig as a way to share common settings like encoding, indentation style or which character to use for line-endings. Throughout our projects we use this config:

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true

Prettier

Prettier is a tool for automatic code formatting. For a complete list of supported languages head over to their docs. If you're unsure what it does, you can try it online without any installations via the playground.

Usage

Install prettier in your project:

npm install --save-dev prettier

Add .prettierrc file at the root directory with the following content:

{
  "trailingComma": "all",
  "singleQuote": true
}

Editor Plugins

We highly recommend to install the relevant plugin for your editor of choice to enable formatting on save. Please follow the installation instructions of the plugins README.

Please consult the official docs for more information like on how to ignoring code and other topics.

Besides the IDE-Plugins we recommend setting up a pre-commit so that only formatted code finds its way into the repository. Please read the docs about Git-Hooks for instructions on how to do so.

Stylelint

With the advent of various compile to CSS languages, stylelint has been created to support a one size fits all linting solution for all your style-related files. It follows the footsteps of previous libraries like sass-lint and scss-lint.

Usage

Install stylelint in your project:

npm install --save-dev stylelint stylelint-config-sevenval

Add the configuration file stylelint.config.js with the following content:

module.exports = {
  extends: 'stylelint-config-sevenval',
};

If you need to further customise the ruleset for your project you can look into the official docs.

Editor Plugins

ESLint

ESLint has been the standard for lining JavaScript-based code for quite a while. It enjoys a solid standing throughout the whole Open-Source Community being known for it's rock solid support.

Usage

Installing eslint:

npm install --save-dev eslint eslint-config-sevenval

Add the configuration file .eslintrc with the following content:

{
  "extends": "eslint-config-sevenval"
}

If you need to further customise the ruleset for your project you can look into the official docs.

Editor Plugins

TSLint

TSLint works similarly as ESLint just for TypeScript.

Usage

Installing eslint:

npm install --save-dev tslint tslint-config-sevenval

Add the configuration file tslint.json with the following content:

{
  "extends": "tslint-config-sevenval"
}

If you need to further customise the ruleset for your project you can look into the official docs.

Editor Plugins

Git Hooks

Git hooks can be used to execute arbitrary scripts or commands on git events. The most popular one is the pre-commit hook which runs just before a git commit is created. We recommend create a pre-commit hook for prettier so that only formatted code can enter the repository.

If there isn't already a git hook pipeline setup in your project we suggest setting them up via husky and lint-staged. Note that for backend projects that are not based on nodejs you'll likely encounter different tools for setting up git hooks.

npm install --save-dev husky

Husky is used to execute npm scripts defined in package.json as a git hook.

{
  "name": "my-project",
  "husky": {
    "hooks": {
      "pre-commit": "echo 'hello world'"
    }
  },
  "devDependencies": {
    "husky": "^x.x.x"
  }
}

This will output hello world before creating a commit.

If you execute commands that expect an files as input like it is commonly done with linters, you do not want to lint the whole repository. Instead developers only want to check the files that are staged in git. This is a lot more performant and ensures a less invasive workflow change.

For that we have made great experiences with lint-staged.

npm install --save-dev lint-staged

After the package is installed you can enable it via extending package.json. This config tells lint stage to always run prettier if the staged file ends with .js, .json, .css or .scss:

{
  "name": "my-project",  
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{js,json,css,scss}": ["prettier --write", "git add"]
  },
  "devDependencies": {
    "husky": "^x.x.x",
    "lint-staged": "^x.x.x"
  }
}

frontend-configs's People

Contributors

fabianmebus avatar kr1sp1n avatar marvinhagemeister avatar rubengarcia-sevenval avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

frontend-configs's Issues

prettierrc shouldn't set trailingComma to "all"

trailing commas on function signatures are not spec conform whereas the ie11 throws a syntax error when it finds that. this will work only if a babel pre-processor is used for building applications, which then in return removes the trailing commas.

in my opinion it would make more sense to set this option to "es5" which sets the trailing comma only for objects and arrays but keeps the function signature clean.

eslint-config-sevenval peer dependencies

Installation as documented:

$ npm install --save-dev eslint eslint-config-sevenval
npm notice created a lockfile as package-lock.json. You should commit this file.
  npm WARN [email protected] requires a peer of [email protected] but none is installed. You must install peer dependencies yourself.

+ [email protected]
+ [email protected]
added 207 packages from 142 contributors and audited 451 packages in 20.981s
found 0 vulnerabilities

It is not possible to lint your files with this config without having the peer dependencies installed:

$ eslint foo.js
Warning: React version not specified in eslint-plugin-react settings. See https://github.com/yannickcr/eslint-plugin-react#configuration.

I guess it is a good idea to remove the peer dependencies.

Deprecate npm packages

As of now, installing e.g. sevenval-config-eslint via npm does not throw a deprecation warning. It would be good to have a warning that informs about the superseding packages.

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.