Skip to content

Commit

Permalink
Upgrade to eslint v9
Browse files Browse the repository at this point in the history
Also:

- Use npm instead of yarn
- Add `.editorconfig`
- Add `release-it`
- Simplify scripts
- Do not depend on uphold eslint config
  • Loading branch information
satazor committed Oct 16, 2024
1 parent 9685f97 commit 6af4763
Show file tree
Hide file tree
Showing 16 changed files with 5,077 additions and 3,724 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]

# Change these settings to your own preference
indent_style = space
indent_size = 2

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

# Markdown specific settings
[*.md]
trim_trailing_whitespace = false
10 changes: 0 additions & 10 deletions .eslintrc.js

This file was deleted.

12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: ['14', '16']
node: ['20', '22']
name: Node ${{ matrix.node }}

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: yarn install --frozen-lockfile
- run: yarn lint
- run: yarn test
- run: npm ci
- run: npm run lint
- run: npm test
47 changes: 47 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Release

on:
workflow_dispatch:
inputs:
VERSION_BUMP:
description: 'The version bump'
type: choice
options:
- major
- minor
- patch
default: minor
required: true

jobs:
release:
runs-on: ubuntu-latest
concurrency: "1"
environment: release

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.RELEASE_GITHUB_TOKEN }}

- name: Setup Node.js version
uses: actions/setup-node@v4
with:
node-version: 22

- name: Install dependencies
run: npm ci

- name: Configure git
run: |
git config user.name "Uphold"
git config user.email "[email protected]"
- name: Generate release
env:
NPM_TOKEN: ${{ secrets.RELEASE_NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }}
run: |
echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
npm run release -- --increment ${{ github.event.inputs.VERSION_BUMP }} -V
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.eslintcache
yarn.lock
21 changes: 21 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"git": {
"changelog": "echo \"## Changelog\\n\\n$(npx @uphold/github-changelog-generator -f unreleased | tail -n +4 -f)\"",
"requireCleanWorkingDir": false,
"commitMessage": "Release `v${version}`",
"requireBranch": "master",
"requireCommits": true,
"tagName": "v${version}"
},
"github": {
"release": true,
"releaseName": "v${version}"
},
"hooks": {
"after:bump": [
"touch CHANGELOG.md",
"echo \"$(npx @uphold/github-changelog-generator -f v${version})\n$(tail -n +2 CHANGELOG.md)\" > CHANGELOG.md",
"git add CHANGELOG.md --all"
]
}
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Uphold Inc.
Copyright (c) 2024 Uphold Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
54 changes: 36 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This plugin is a drop-in replacement to `sort-imports` with a few extra features
You'll first need to install [ESLint](https://eslint.org/):

```sh
npm i eslint --save-dev
npm i eslint --save-dev
```

Next, install `eslint-plugin-sort-imports-requires`:
Expand All @@ -33,25 +33,23 @@ Next, install `eslint-plugin-sort-imports-requires`:

## Usage

Add `sort-imports-requires` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
Add `sort-imports-requires` to the plugins section of your ESLint configuration file and configure its rules. Here's an example:

```json
{
"plugins": [
"sort-imports-requires"
]
}
```

Then configure the rules you want to use under the rules section.

```json
{
"rules": {
"sort-imports-requires/sort-imports": "error",
"sort-imports-requires/sort-requires": "error"
```js
// eslint.config.js
import sortImportRequires from 'eslint-plugin-sort-imports-requires';

export default [
{
plugins: {
'sort-imports-requires': sortImportRequires
},
rules: {
'sort-imports-requires/sort-imports': ['error', { unsafeAutofix: true }],
'sort-imports-requires/sort-requires': ['error', { unsafeAutofix: true }]
}
}
}
];
```

## Supported Rules
Expand Down Expand Up @@ -95,6 +93,26 @@ Whether to restore the old ESLint behavior where `multiple` type corresponds to

[MIT](https://opensource.org/licenses/MIT)

## Contributing

### Development

Install dependencies:

```bash
npm i
```

Run tests:

```bash
npm run test
```

### Cutting a release

The release process is automated via the [release](https://github.com/uphold/eslint-plugin-sort-imports-requires/actions/workflows/release.yaml) GitHub workflow. Run it by clicking the "Run workflow" button.

[npm-image]: https://img.shields.io/npm/v/eslint-plugin-sort-imports-requires.svg
[npm-url]: https://www.npmjs.com/package/eslint-plugin-sort-imports-requires
[ci-image]: https://github.com/uphold/eslint-plugin-sort-imports-requires/actions/workflows/ci.yml/badge.svg?branch=master
Expand Down
31 changes: 31 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
const globals = require('globals');
const js = require('@eslint/js');
const sortImportsRequires = require('.');

module.exports = [
js.configs.recommended,
eslintPluginPrettierRecommended,

{
plugins: {
'sort-imports-requires': sortImportsRequires
},
rules: {
'prettier/prettier': [
'error',
{
arrowParens: 'avoid',
printWidth: 120,
singleQuote: true,
trailingComma: 'none'
}
],
'sort-imports-requires/sort-imports': ['error', { unsafeAutofix: true }],
'sort-imports-requires/sort-requires': ['error', { unsafeAutofix: true }]
},
languageOptions: {
globals: globals.node
}
}
];
11 changes: 8 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
module.exports.rules = {
'sort-imports': require('./rules/sort-imports'),
'sort-requires': require('./rules/sort-requires')
module.exports = {
meta: {},
configs: {},
rules: {
'sort-imports': require('./rules/sort-imports'),
'sort-requires': require('./rules/sort-requires')
},
processors: {}
};
2 changes: 0 additions & 2 deletions lib/utils/sort-rule-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const buildSortRule = (ruleType, ruleTypeFns, processNode) => ({
};
},
meta: {
/* eslint-disable sort-keys */
type: 'suggestion',
docs: {
description: `enforce sorted ${ruleType} declarations within modules`,
Expand Down Expand Up @@ -98,7 +97,6 @@ const buildSortRule = (ruleType, ruleTypeFns, processNode) => ({
sortMembersAlphabetically: `Member '{{memberName}}' of the ${ruleType} declaration should be sorted alphabetically.`,
unexpectedSyntaxOrder: `Expected ${ruleType} declaration of '{{syntaxA}}' syntax to be placed before '{{syntaxB}}' syntax.`
}
/* eslint-enable sort-keys */
}
});

Expand Down
Loading

0 comments on commit 6af4763

Please sign in to comment.