npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@buildinams/lint

v0.4.2

Published

BiA's base lint config(s).

Downloads

955

Readme

lint

NPM version Actions Status PR Welcome

BiA's base lint config(s).

Installation

Install this package with npm.

npm i -D @buildinams/lint

Usage

This package export six base ESLint, one Prettier and one base Stylelint configuration:

  • JavaScript (@buildinams/lint/eslint/javascript)
  • Typescript (@buildinams/lint/eslint/typescript)
  • React.js JavaScript (@buildinams/lint/eslint/react-javascript)
  • Next.js JavaScript (@buildinams/lint/eslint/next-javascript)
  • React.js TypeScript (@buildinams/lint/eslint/react-typscript)
  • Next.js TypeScript (@buildinams/lint/eslint/next-typescript)
  • Base Prettier (@buildinams/lint/prettier)
  • SCSS with CSS Modules (@buildinams/lint/stylelint)

ESLint

@buildinams/lint/eslint

This is our base config for all React projects. It extends:

To use the shared eslint configuration, create an .eslintrc.json in your root project directory, and extend the config:

{
	"extends": "./node_modules/@buildinams/lint/eslint/react-javascript"
}

@buildinams/lint/eslint/react-typescript

This extends our base React config with parsing / linting support for TypeScript from @typescript-eslint/recommended.

To use, create a .eslintrc.json and extend the config:

{
	"extends": "./node_modules/@buildinams/lint/eslint/react-typescript"
}

@buildinams/lint/eslint/next

This is our base configuration for all Next.js projects. It extends:

To use, create a .eslintrc.json and extend the config:

{
	"extends": "./node_modules/@buildinams/lint/eslint/next-javascript"
}

@buildinams/lint/eslint/next-typescript

This extends our base Next config with parsing / linting support for TypeScript from @typescript-eslint/recommended.

To use, create a .eslintrc.json and extend the config:

{
	"extends": "./node_modules/@buildinams/lint/eslint/next-typescript"
}

Extended ESLint Rules

The idea behind this config is to enforce consistency across all projects. We've tried to keep the rules as minimal as possible, and for the most part simply inherit from the recommended rules of the plugins we use. The main exceptions are when it comes to the following. Note: We've purposely only defined rules that are auto fixable, these rules should make it easier to write code, and not get in the way. With one Typescript exception.

eslint-plugin-unused-imports

This is used to enforce that all imports are used in the file. This is used to prevent unused imports from being committed to the repo.

eslint-plugin-simple-import-sort

This is used to enforce a consistent import order. The following order has been defined:

  1. External modules (e.g. react, next and @buildinams/)
  2. Absolute imports (supports prefix of _ and ~ e.g. public/, _components and ~/contexts)
  3. Relative imports (e.g. ../ and ./)

Note: The biggest thing we enforce here is the use of prefixes (either _ or ~) for absolute imports. This is to make it clear that these are not external modules, and to make it easier to distinguish between the different modules when enforcing the import order.

eslint-plugin-import

This is used to auto fix some common inconsistencies. The following rules have been enabled:

@typescript-eslint/consistent-type-definitions

Used to enforce type over interface, the difference between interface and type is minimal and the one additional feature it supports we shouldn't use.

no-restricted-syntax

  • TSEnumDeclaration - Error when using Enums, let's push for const Foo as const since it's more declarative that it outputs JS. Enums are in a weird in between state that they are both types and constants. This makes them confusing on how to use them and what the output will be.

Note: The TSEnumDeclaration is our only rule that can't be auto-fixed by Eslint. This is because based on what we need the enum for the 'correct' approach might differ.

Prettier

@buildinams/lint/prettier

Our base prettier setup, it doesn't have any custom plugins at this point but we do modify two rules, explained below.

To use, create a .prettierrc.js in the root of your project and export the config from the package;

module.exports = require("./node_modules/@buildinams/lint/prettier");

Trailing comma; "all"

Keeps the trailing comma around wherever possible. Advantages; less changes in Git when adding a row, more flexible when changing the order of entries in; arrays, objects and function arguments. Alternative value: "es5", we have a compile step so we can write "future" JS in our source code without worries.

Tabs

Tabs over spaces, spaces have a fixed width and tabs can be whatever the developer wants it to be using a custom tabWidth value.

Quotes

We enforce the use of "double quotes" when possible. We defined this with the intent of it being applied as a auto-fixable rule to enforce consistency with prettier.

Stylelint

@buildinams/lint/stylelint

This is our base config for all SCSS projects with CSS Modules. It extends:

For the most part we've tried to simply inherit rules from the above configs, but we've also added a few custom rules:

To use, create a .stylelintrc.json and extend the config:

{
	"extends": "./node_modules/@buildinams/lint/stylelint"
}

Lastly, this config also enforces scss/function-no-unknown to prevent the use of unknown functions. As you define functions in your project, we recommend you add them to the ignoreFunctions array in the config. For example:

{
	"extends": "./node_modules/@buildinams/lint/stylelint",
	"rules": {
		"scss/function-no-unknown": [true, { "ignoreFunctions": ["px-to-rem"] }]
	}
}

This adds a level of type safety to your SCSS, and prevents developers from using functions that don't 'exist'.

Using 'tab' Spacings

Different developers have different preferences when it comes down to spacing sizes. To make sure everyone can have what they want visually, we've decided to enforce tabs over spaces. This means one developer can have tabs render as 4 spaces and another as 2 spaces without it effecting the codebase.

Using With Prettier

As you'll notice, this package doesn't contain any custom .pretterrc.json config to extend. We recommend not including it, and instead just inheriting the default config (by not creating / changing it).

Enabling Prettier on Save in VSCode

To use Prettier on save, you'll need to install the following VSCode extensions:

To then enable format on save in VScode, open your workspace settings (Shift-Command-P and select Open Workspace Settings (JSON)), then paste the following into /.vscode/settings.json:

{
	"editor.formatOnSave": false,
	"editor.defaultFormatter": "esbenp.prettier-vscode",
	"editor.codeActionsOnSave": {
		"source.fixAll.eslint": "explicit"
	}
}

Enabling Stylelint on Save in VSCode

To use Stylelint on save, you'll need to install the stylelint.vscode-stylelint extension.

To then enable format on save in VScode, open your workspace settings (see above for how to open workspace settings), then paste the following into /.vscode/settings.json:

{
	"editor.formatOnSave": false,
	"scss.validate": false,
	"stylelint.validate": ["scss"],
	"editor.codeActionsOnSave": {
		"source.fixAll.stylelint": "explicit"
	}
}

Requirements

This library requires a minimum React version of 17.0.0.

Requests and Contributing

Found an issue? Want a new feature? Get involved! Please contribute using our guideline here.