Skip to content

Commit

Permalink
feat: initial rules
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Jun 7, 2020
1 parent 0a02bf7 commit 4267c5c
Show file tree
Hide file tree
Showing 32 changed files with 19,127 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!.eslintrc.js
coverage
lib
30 changes: 30 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/** @type {import('eslint').Linter.Config} */
const config = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
ecmaVersion: 2019,
sourceType: 'module'
},
env: { node: true },
plugins: ['eslint-plugin'],
extends: ['ackama', 'ackama/@typescript-eslint'],
ignorePatterns: ['!.eslintrc.js', 'coverage', 'lib'],
overrides: [
{
files: ['test/**'],
extends: ['ackama/jest'],
rules: {
'jest/prefer-expect-assertions': 'off'
}
}
],
rules: {
'import/no-deprecated': 'error',
'@typescript-eslint/no-unsafe-assignment': 'error',
'@typescript-eslint/prefer-reduce-type-parameter': 'error'
}
};

module.exports = config;
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
18 changes: 18 additions & 0 deletions .github/eslint-compact.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"problemMatcher": [
{
"owner": "eslint-compact",
"pattern": [
{
"regexp": "^(.+):\\sline\\s(\\d+),\\scol\\s(\\d+),\\s(Error|Warning|Info)\\s-\\s(.+)\\s\\((.+)\\)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5,
"code": 6
}
]
}
]
}
22 changes: 22 additions & 0 deletions .github/eslint-stylish.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"problemMatcher": [
{
"owner": "eslint-stylish",
"pattern": [
{
"regexp": "^([^\\s].*)$",
"file": 1
},
{
"regexp": "^\\s+(\\d+):(\\d+)\\s+(error|warning|info)\\s+(.*)\\s\\s+(.*)$",
"line": 1,
"column": 2,
"severity": 3,
"message": 4,
"code": 5,
"loop": true
}
]
}
]
}
87 changes: 87 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Checks
on:
push:
branches:
- master
- next
pull_request:
branches:
- master
- next

env:
# reduces noise from npm post-install scripts
DISABLE_OPENCOLLECTIVE: true
OPEN_SOURCE_CONTRIBUTOR: true

jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Commit Linter
uses: wagoid/commitlint-github-action@v1.3.1
with:
configFile: './package.json'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

test-node:
name:
# prettier-ignore
Test on Node.js v${{ matrix.node-version }} and eslint v${{matrix.eslint-version }}
strategy:
fail-fast: false
matrix:
node-version: [8.x, 10.x, 12.x, 13.x, 14.x]
eslint-version: [6, 7]
exclude:
# eslint@7 doesn't support node@8
- node-version: 8.x
eslint-version: 7
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: install with eslint v${{matrix.eslint-version }}
run: |
npm ci
npm install -D eslint@${{matrix.eslint-version }}
- name: prettylint
run: npm run prettylint
- name: typecheck
run: npm run typecheck
- name: test
run: npm run test --coverage
env:
CI: true

test-os:
name: Test on ${{ matrix.os }} using Node.js LTS
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
- name: install
run: npm ci
- name: prettylint
run: npm run prettylint
- name: typecheck
run: npm run typecheck
- name: test
run: npm run test --coverage
env:
CI: true
43 changes: 43 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Release
on:
push:
branches:
- master

env:
# reduces noise from npm post-install scripts
DISABLE_OPENCOLLECTIVE: true
OPEN_SOURCE_CONTRIBUTOR: true

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'

- uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: install
run: npm ci
- name: prettylint
run: npm run prettylint
- name: typecheck
run: npm run typecheck
- name: test
run: npm run test --coverage
env:
CI: true

- name: release
run: npm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
7 changes: 7 additions & 0 deletions .huskyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "http://json.schemastore.org/huskyrc",
"hooks": {
"commit-msg": "commitlint -e $HUSKY_GIT_PARAMS",
"pre-commit": "lint-staged"
}
}
5 changes: 5 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"**/*.{t,j}s": "eslint --fix",
"**/.eslint{rc,ignore}": "npm run lint",
"**/*.{md,json}": "prettier --write"
}
98 changes: 98 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<div align="center">
<a href="https://eslint.org/">
<img
width="150"
height="150"
src="https://eslint.org/assets/img/logo.svg"
alt="ESLint Logo"
/>
</a>
<h1>eslint-plugin-eslint-config</h1>
<p>ESLint plugin for ESLint configs</p>
</div>

This plugin provides rules for linting files that export configs meant for use
with ESLint, to ensure that they're valid.

## Installation

npm install --dev eslint eslint-plugin-eslint-config

**Note:** If you installed ESLint globally then you must also install
`eslint-plugin-eslint-config` globally.

## Usage

Add `config` to the plugins section of your `.eslintrc.js` configuration file.
You can omit the `eslint-plugin-` prefix:

```json
{
"plugins": ["eslint-config"]
}
```

Then configure the rules you want to use _for your config(s)_ using `overrides`:

```json
{
"overrides": [
{
"files": [".eslintrc.js", "react.js", "@typescript-eslint.js"],
"rules": {
"eslint-config/no-deprecated-rules": "warn"
}
}
]
}
```

The rules assume that the files they're linting are configs meant for ESLint.

## Shareable configurations

This plugin provides three presets:

- `recommended-rules`
- `rc`
- `all`

The `rc` preset generally should be used by all projects, as it applies
recommended rules to supported eslintrc files.

If a project contains other files that export eslint configs (such as an eslint
config package), the `recommended-rules` preset can be used to apply the
recommended rules to those files using `overrides`.

<!-- The reason behind having two presets instead of the standard `recommended`
preset is because the rules provided by this plugin work by executing the source
code that they're linting to capture the configuration they export that gets
used by eslint.
This means that they can trigger side effects in the same way importing a file
might, and so should not be applied to every file in a code base.
To facilitate this ESLint allows configs to provide an `overrides` property that
applies rules to files based on globs (which is what `eslint-config/rc` does),
but while shared configs can use `overrides` there isn't a way to nicely to add
to the glob patterns to reuse the rules. -->

While the `recommended` and `rc` configurations only change in major versions,
the `all` configuration may change in any release and is thus unsuited for
installations requiring long-term consistency.

## Rules

<!-- begin rules list -->

| Rule | Description | Configurations | Fixable |
| -------------------------------------------------------- | --------------------------------------------------- | ---------------- | ------------ |
| [no-deprecated-rules](docs/rules/no-deprecated-rules.md) | Checks for usage of deprecated eslint rules | ![recommended][] | |
| [no-invalid-config](docs/rules/no-invalid-config.md) | Checks that the config exported by a file is valid | ![recommended][] | |
| [no-unknown-rules](docs/rules/no-unknown-rules.md) | Ensures that all rules are known | ![recommended][] | |
| [sort-rules](docs/rules/sort-rules.md) | Ensures that rules are sorted in a consistent order | | ![fixable][] |

<!-- end rules list -->

[recommended]: https://img.shields.io/badge/-recommended-lightgrey.svg
[fixable]: https://img.shields.io/badge/-fixable-green.svg
10 changes: 10 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

// todo: https://github.com/babel/babel/issues/8529 :'(
module.exports = {
plugins: ['replace-ts-export-assignment'],
presets: [
'@babel/preset-typescript',
['@babel/preset-env', { targets: { node: 8 } }]
]
};
39 changes: 39 additions & 0 deletions docs/rules/no-deprecated-rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Checks for usage of deprecated eslint rules (`no-deprecated-rules`)

## Rule details

This rule checks for rules that have been marked as deprecated, and suggests
their replacements, if any.

Note that this rule, like others of its kind, works by mapping the results of
running the configs through ESLint to rule ids, and then checking every object
property in the file being linted against these rule ids.

This means that if a deprecated rule is used anywhere in the exported config,
then _all_ the places that rule id is used be highlighted.

For example:

```js
const rules = {
'@typescript-eslint/camelcase': 'warn'
};

module.exports = {
plugins: ['@typescript-eslint'],
overrides: [
{
files: ['*.tsx'],
rules: {
'@typescript-eslint/camelcase': 'off'
}
}
],
rules: {
'@typescript-eslint/camelcase': 'error'
}
};
```

In the above configuration, all three `'@typescript-eslint/camelcase'`
properties would be marked.
Loading

0 comments on commit 4267c5c

Please sign in to comment.