Skip to content

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
hiukky committed Apr 2, 2021
2 parents f283fd6 + fec450f commit 2e8d44b
Show file tree
Hide file tree
Showing 14 changed files with 446 additions and 557 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn commitlint --edit
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn test
7 changes: 0 additions & 7 deletions .huskyrc

This file was deleted.

3 changes: 1 addition & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
node_modules
tests
lib
.eslintrc.json
.eslintrc
commitlint.config.js
jest.config.js
.prettierrc
.prettierignore
.huskyrc
.editorconfig
.gitignore
tsconfig.json
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<h1 align="center"> eslint-plugin-hooks-sort </h1>
<h1 align="center"> eslint-plugin-hooks </h1>

<p align="center">
<a href="https://travis-ci.org/github/hiukky/eslint-plugin-hooks-sort">
<img alt="Build" src="https://img.shields.io/github/workflow/status/hiukky/eslint-plugin-hooks-sort/build?color=%2323d18c&style=for-the-badge&colorA=1C1D27">
<a href="https://travis-ci.org/github/hiukky/eslint-plugin-hooks">
<img alt="Build" src="https://img.shields.io/github/workflow/status/hiukky/eslint-plugin-hooks/build?color=0d1117&style=for-the-badge&colorA=1C1D27">
</a>
<a href="https://github.com/hiukky/eslint-plugin-hooks-sort/stargazers">
<img alt="GitHub stars" src="https://img.shields.io/github/stars/hiukky/eslint-plugin-hooks-sort?color=%2300cecb&style=for-the-badge&colorA=1C1D27">
<a href="https://github.com/hiukky/eslint-plugin-hooks/stargazers">
<img alt="GitHub stars" src="https://img.shields.io/github/stars/hiukky/eslint-plugin-hooks?color=0d1117&style=for-the-badge&colorA=1C1D27">
</a>
<a href="https://github.com/hiukky/eslint-plugin-hooks-sort/network">
<img alt="GitHub forks" src="https://img.shields.io/github/forks/hiukky/eslint-plugin-hooks-sort?color=%23a29bfe&style=for-the-badge&colorA=1C1D27">
<a href="https://github.com/hiukky/eslint-plugin-hooks/network">
<img alt="GitHub forks" src="https://img.shields.io/github/forks/hiukky/eslint-plugin-hooks?color=0d1117&style=for-the-badge&colorA=1C1D27">
</a>
<a href="https://github.com/hiukky/eslint-plugin-hooks-sort/issues">
<img alt="GitHub issues" src="https://img.shields.io/github/issues/hiukky/eslint-plugin-hooks-sort?style=for-the-badge&color=ffe066&colorA=1C1D27">
<a href="https://github.com/hiukky/eslint-plugin-hooks/issues">
<img alt="GitHub issues" src="https://img.shields.io/github/issues/hiukky/eslint-plugin-hooks?style=for-the-badge&color=0d1117&colorA=1C1D27">
</a>
<a href="httdivs://github.com/hiukky/eslint-plugin-hooks-sort/blob/develop/LICENSE">
<img alt="GitHub license" src="https://img.shields.io/github/license/hiukky/eslint-plugin-hooks-sort?color=%23eab464&style=for-the-badge&colorA=1C1D27" />
<a href="httdivs://github.com/hiukky/eslint-plugin-hooks/blob/develop/LICENSE">
<img alt="GitHub license" src="https://img.shields.io/github/license/hiukky/eslint-plugin-hooks?color=0d1117&style=for-the-badge&colorA=1C1D27" />
</a>
<a href="https://www.npmjs.com/package/eslint-plugin-hooks-sort">
<img alt="NPM" src="https://img.shields.io/npm/dt/eslint-plugin-hooks-sort?color=%23f49e4c&style=for-the-badge&colorA=1C1D27" />
<a href="https://www.npmjs.com/package/eslint-plugin-hooks">
<img alt="NPM" src="https://img.shields.io/npm/dt/eslint-plugin-hooks-sort?color=0d1117&style=for-the-badge&colorA=1C1D27" />
</a>
</p>

Expand All @@ -38,19 +38,19 @@ You'll first need to install [ESLint](http://eslint.org):
$ npm i eslint --save-dev
```

Next, install `eslint-plugin-hooks-sort`:
Next, install `eslint-plugin-hooks`:

```
$ npm install eslint-plugin-hooks-sort --save-dev
$ npm install eslint-plugin-hooks --save-dev
```

## Usage

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

```json
{
"plugins": ["hooks-sort"]
"plugins": ["hooks"]
}
```

Expand All @@ -59,7 +59,7 @@ Then configure the rules you want to use under the rules section.
```json
{
"rules": {
"hooks-sort/order": [
"hooks/sort": [
2,
{
"groups": [
Expand Down
6 changes: 3 additions & 3 deletions docs/rules/order.md → docs/rules/sort.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# A simple organizer for ordering hooks. (order)
# A simple organizer for ordering hooks. (sort)

Please describe the origin of the rule here.

Expand All @@ -10,7 +10,7 @@ Examples of **incorrect** code for this rule:

```js
/**
* "hooks-sort/order": [
* "hooks/sort": [
* 2,
* {
* "groups": [
Expand All @@ -31,7 +31,7 @@ Examples of **correct** code for this rule:

```js
/**
* "hooks-sort/order": [
* "hooks/sort": [
* 2,
* {
* "groups": [
Expand Down
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @fileoverview A simple organizer for ordering hooks.
* @author Hiukky
* @author Romullo @hiukky
*/
'use strict'

Expand Down
28 changes: 13 additions & 15 deletions lib/rules/order.ts → lib/rules/sort.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/**
* @fileoverview A simple organizer for ordering hooks.
* @author Hiukky
* @author Romullo @hiukky
*/
'use strict'

import { TContext, TNode } from './types'
import { IContext, INode } from './types'

const DEFAULT_GROUPS = ['useContext', 'useState', 'useEffect']

module.exports = {
meta: {
docs: {
description: 'A simple organizer for ordering hooks.',
category: 'Non-matching declaration order.',
url:
'https://github.com/hiukky/eslint-plugin-hooks-sort/blob/master/docs/rules/order.md',
'https://github.com/hiukky/eslint-plugin-hooks/blob/master/docs/rules/sort.md',
recommended: false,
},
fixable: undefined,
Expand All @@ -28,17 +30,17 @@ module.exports = {
],
},

create: (ctx: TContext) => {
create: (ctx: IContext) => {
const options = ctx.options[0]
const orderHooks: [string, TNode][] = []
const orderHooks: [string, INode][] = []

return {
/**
* @function VariableDeclaration
*
* @param {TNode} node
* @param {INode} node
*/
VariableDeclaration: (node: TNode) => {
VariableDeclaration: (node: INode) => {
const declaration = node.declarations[0].init

if (
Expand All @@ -55,20 +57,16 @@ module.exports = {
/**
* @function Program
*
* @param {TNode} node
* @param {INode} node
*/
'Program:exit': () => {
var groups: string[] = options?.groups || [
'useContext',
'useState',
'useEffect',
]
var groups: string[] = options?.groups || DEFAULT_GROUPS

const matchingHooks: [string, TNode][] = [...orderHooks].filter(hook =>
const matchingHooks: [string, INode][] = [...orderHooks].filter(hook =>
groups.includes(hook[0]),
)

const orderHooksCorrect: [string, TNode][] = [...matchingHooks].sort(
const orderHooksCorrect: [string, INode][] = [...matchingHooks].sort(
(a, b) => groups.indexOf(a[0]) - groups.indexOf(b[0]),
)

Expand Down
10 changes: 5 additions & 5 deletions lib/rules/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export type TOrderHooksOptions = {
export type IOrderHooksOptions = {
groups: string[]
}

export type TSchemaOptions = TOrderHooksOptions
export type ISchemaOptions = IOrderHooksOptions

export type TContext = {
export type IContext = {
report(node: any, message: string): void
options: TSchemaOptions[]
options: ISchemaOptions[]
}

export type TNode = {
export type INode = {
kind: 'var' | 'let' | 'const'
declarations: {
init: {
Expand Down
60 changes: 32 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,60 +1,64 @@
{
"name": "eslint-plugin-hooks-sort",
"version": "0.1.1",
"name": "eslint-plugin-hooks",
"version": "0.2.0",
"description": "A simple organizer for ordering hooks.",
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin",
"hooks",
"react",
"react-hooks"
],
"main": "dist/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/hiukky/eslint-plugin-hooks-sort.git"
"url": "git+https://github.com/hiukky/eslint-plugin-hooks.git"
},
"bugs": {
"url": "https://github.com/hiukky/eslint-plugin-hooks-sort/issues"
"url": "https://github.com/hiukky/eslint-plugin-hooks/issues"
},
"author": {
"name": "Romullo @hiukky",
"email": "developermarsh@gmail.com",
"url": "https://hiukky.com/"
},
"scripts": {
"prepare": "husky install",
"clean": "rimraf dist typings",
"prebuild": "yarn clean",
"test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register 'tests/**/*.spec.ts' --recursive",
"build": "tsc -d -p .",
"format": "prettier --write \"**/*.ts\""
"format": "prettier --write \"**/*.ts\"",
"prepublishOnly": "pinst --disable",
"postpublish": "pinst --enable"
},
"dependencies": {
"requireindex": "~1.2.0"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@types/chai": "^4.2.14",
"@types/eslint": "^7.2.6",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.19",
"@types/react": "^17.0.0",
"@commitlint/cli": "^12.1.1",
"@commitlint/config-conventional": "^12.1.1",
"@types/chai": "^4.2.15",
"@types/eslint": "^7.2.8",
"@types/mocha": "^8.2.2",
"@types/node": "^14.14.37",
"@types/react": "^17.0.3",
"@types/requireindex": "^1.2.0",
"@typescript-eslint/eslint-plugin": "^4.11.1",
"eslint": "^7.17.0",
"husky": "^4.3.6",
"mocha": "^8.2.1",
"@typescript-eslint/eslint-plugin": "^4.20.0",
"eslint": "^7.23.0",
"eslint-config-airbnb-base": "^14.2.1",
"husky": "^6.0.0",
"mocha": "^8.3.2",
"pinst": "^2.1.6",
"prettier": "^2.2.1",
"react": "^17.0.1",
"react": "^17.0.2",
"rimraf": "^3.0.2",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"eslint-config-airbnb-base": "^14.2.1"
"typescript": "^4.2.3"
},
"engines": {
"node": ">=0.10.0"
},
"license": "MIT"
"license": "MIT",
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin",
"hooks",
"react",
"react-hooks"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'use strict'

import { RuleTester } from 'eslint'
import * as rule from '../../../lib/rules/order'
import * as rule from '../../../lib/rules/sort'

const Tester = new RuleTester()

Expand Down
Loading

0 comments on commit 2e8d44b

Please sign in to comment.