# eslint-config-codecraft

> Codecraft.dev ESLint config

Latest version **1.0.0** (published 2022-12-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install eslint-config-codecraft
pnpm add eslint-config-codecraft
yarn add eslint-config-codecraft
bun add eslint-config-codecraft
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-12-05 |
| First published | 2022-12-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Luka Maljic |
| Maintainers | malj |

## Links

- npm: https://www.npmjs.com/package/eslint-config-codecraft
- npm.io page: https://npm.io/package/eslint-config-codecraft

## Recent versions

- 1.0.0 (latest) — 2022-12-05

## README

# [Codecraft](https://codecraft.dev/) ESLint config

[ESLint](https://eslint.org/) config which sets up [EditorConfig](https://editorconfig.org/) + [Prettier](https://prettier.io/) to run as part of the linting process. It also automatically [sorts imports](https://github.com/lydell/eslint-plugin-simple-import-sort) and adds a few opinionated [linting rules](#linting-rules).

## Install

```sh
npm i -D eslint-config-codecraft
```

## Usage

1. Add an `.editorconfig` file in the project root.

	> For example, to use UTF-8 encoding with Unix style newlines, 4 space indentation, and strict whitespace formatting:

	```
	root = true

	[*]
	indent_style = space
	indent_size = 4
	end_of_line = lf
	charset = utf-8
	trim_trailing_whitespace = true
	insert_final_newline = true
	max_line_length = 80
	```

2. Optionally add a `.prettierrc` file in the project root to configure any options which are not inherited from EditorConfig.

	> For example, to omit semicolons and use single quotes for strings:

	```json
	{
		"semi": false,
		"singleQuote": true
	}
	```

3. Add `codecraft` as the _last_ extension in your `.eslintrc.json`:

	```json
	{
		"extends": [
			// ...
			"codecraft"
		]
	}
	```

## Linting rules

A few opinionated rules have been introduced to improve consistency with idioms in other programming languages, and reduce developers' cognitive load when switching between them.

### Strict equality

This rule prohibits the usage of loose equality operators to avoid ambiguity and potential errors.

```js
// GOOD
foo === bar
foo !== bar
```

```js
// BAD
foo == bar
foo != bar
```

Rationale:

- [When is it OK to use == in JavaScript?](https://2ality.com/2011/12/strict-equality-exemptions.html)


### Block scoped variables

This configuration prohibits usage of `var` due to its unintuitive scoping, and enforces usage of block scoped variables. However, unlike common recommendations, it favors `let` keyword instead of `const` in almost all cases, to improve semantics and consistency with other mutable storage (function arguments, object properties).

```js
// GOOD
const TOP_LEVEL_CONSTANT = "foo"
let topLevelVariable = "bar"

function nestedScope() {
	let nestedVariable = "baz"
}
```

```js
// BAD
function nestedScope() {
	const NESTED_CONSTANT = "foo"
}
```

Rationale:

- [Use "let" by default, not "const"](https://medium.com/@PepsRyuu/use-let-by-default-not-const-58773e53db52)
- [Semantic usage of "let" and "const"](https://github.com/thefrontside/javascript/blob/v3/packages/eslint-plugin-prefer-let/README.md)


## Tips

### Pre-commit hook

Format files via NPM's Git pre-commit hook in `package.json`:

```json
{
	"scripts": {
		"precommit": "eslint"
	}
}
```

### Automatic formatting

If using VSCode, install the official [ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and add the following options to your project settings to automatically format files on save:

```json
{
	"editor.formatOnSave": true,
	"eslint.format.enable": true,
	"[javascript]": {
		"editor.defaultFormatter": "dbaeumer.vscode-eslint"
	}
}
```

---
_Source: https://npm.io/package/eslint-config-codecraft · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
