Skip to content

Commit dba13cc

Browse files
authored
Tooling updates, types and removing unneeded files from the published package (#113)
Change package manager: Switch yarn v1 to pnpm Change test runner: Switch mocha to using node's built-in test runner Use latest versions of eslint and prettier Move dependabot config into .github and make it group updates Add Actions workflow for running tests and linting Two package output changes: Add types in index.d.ts Add files array in package.json so the published package only includes the index.{js,d.ts} files
1 parent 71259f6 commit dba13cc

13 files changed

Lines changed: 1024 additions & 881 deletions

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

.github/CONTRIBUTING.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,39 @@ Thanks for contributing!
77
```sh
88
git clone https://github.com/prettier/prettier-linter-helpers.git
99
cd prettier-linter-helpers
10-
yarn install
10+
pnpm install
1111
```
1212

13-
## Running the tests
13+
## Running the tests and linters
14+
15+
Run tests:
1416

1517
```sh
16-
yarn run test
18+
pnpm run test
1719
```
1820

19-
Linting is ran as part of `yarn run test`. The build will fail if there are any linting errors. You can run `yarn run lint --fix` to fix some linting errors (including formatting to match prettier's expectations). To run the tests without linting run `yarn run test`.
21+
Run linters:
22+
23+
```sh
24+
pnpm run lint
25+
```
2026

2127
## Publishing
2228

23-
- Ensure you are on the master branch locally.
29+
- Ensure you are on the `main` branch locally.
2430
- Update `CHANGELOG.md` and commit.
2531
- Run the following:
2632

2733
```sh
28-
yarn publish
34+
pnpm publish
2935
git push --follow-tags
3036
```
3137

32-
Running `yarn publish` shall:
33-
38+
Running `pnpm publish` shall:
3439
- Bump the version in package.json (asking you for the new version number)
3540
- Create a new commit containing that version bump in package.json
3641
- Create a tag for that commit
3742
- Publish to the npm repository
3843

3944
Running `git push --follow-tags` shall:
40-
4145
- Push the commit and tag to GitHub

.github/dependabot.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: npm
4+
directory: /
5+
schedule:
6+
interval: monthly
7+
groups:
8+
dev-dependencies:
9+
dependency-type: development
10+
patterns:
11+
- '*'
12+
13+
- package-ecosystem: github-actions
14+
directory: /
15+
schedule:
16+
interval: monthly
17+
groups:
18+
actions:
19+
patterns:
20+
- '*'

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: CI
2+
3+
on:
4+
pull_request: ~
5+
push:
6+
branches: [main]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
ci:
14+
name: Lint and Test on Node ${{ matrix.node }}
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
node:
20+
- 24
21+
- 22
22+
- 20
23+
24+
steps:
25+
- name: Checkout Repo
26+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
27+
28+
- name: Setup pnpm
29+
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
30+
31+
- name: Setup Node.js ${{ matrix.node }}
32+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
33+
with:
34+
node-version: ${{ matrix.node }}
35+
cache: pnpm
36+
37+
- name: Install
38+
run: pnpm install --prefer-frozen-lockfile
39+
40+
- name: Test
41+
run: pnpm run test
42+
43+
- name: Lint
44+
run: pnpm run lint

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
package.json
2+
pnpm-lock.yaml

dependabot.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

eslint.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const {defineConfig} = require('eslint/config');
2+
const js = require('@eslint/js');
3+
const eslintPluginN = require('eslint-plugin-n');
4+
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
5+
6+
module.exports = defineConfig([
7+
{
8+
plugins: {js, n: eslintPluginN},
9+
extends: ['js/recommended', 'n/flat/recommended-script'],
10+
},
11+
eslintPluginPrettierRecommended,
12+
// Internal files
13+
{
14+
files: ['test/**', 'eslint.config.js'],
15+
settings: {node: {version: '20.13.0'}},
16+
rules: {'n/no-unpublished-require': 'off'},
17+
},
18+
]);

index.d.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Converts invisible characters to a commonly recognizable visible form.
3+
* @param str - The string with invisibles to convert.
4+
* @returns The converted string.
5+
*/
6+
export function showInvisibles(str: string): string;
7+
8+
export interface Difference {
9+
operation: 'insert' | 'delete' | 'replace';
10+
offset: number;
11+
insertText?: string | undefined;
12+
deleteText?: string | undefined;
13+
}
14+
15+
export interface GenerateDifferences {
16+
/**
17+
* Generate results for differences between source code and formatted version.
18+
*
19+
* @param source - The original source.
20+
* @param prettierSource - The Prettier formatted source.
21+
* @returns An array containing { operation, offset, insertText, deleteText }
22+
*/
23+
(source: string, prettierSource: string): Difference[];
24+
INSERT: 'insert';
25+
DELETE: 'delete';
26+
REPLACE: 'replace';
27+
}
28+
29+
export const generateDifferences: GenerateDifferences;

package.json

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
"Teddy Katz"
88
],
99
"main": "index.js",
10+
"types": "index.d.ts",
1011
"license": "MIT",
1112
"scripts": {
12-
"lint": "eslint .",
13-
"test": "npm run lint && mocha",
14-
"format": "yarn run prettier '**/*.{js,json,md,yml}' --write && yarn run lint --fix"
13+
"lint": "eslint . && prettier . --check",
14+
"test": "node --test test/*.test.js",
15+
"format": "eslint . --fix && prettier '**/*.{js,json,md,yml}' --write"
1516
},
1617
"repository": {
1718
"type": "git",
@@ -21,18 +22,23 @@
2122
"url": "https://github.com/prettier/prettier-linter-helpers/issues"
2223
},
2324
"homepage": "https://github.com/prettier/prettier-linter-helpers#readme",
25+
"files": [
26+
"index.js",
27+
"index.d.ts"
28+
],
2429
"dependencies": {
2530
"fast-diff": "^1.1.2"
2631
},
2732
"devDependencies": {
28-
"eslint": "^5.6.1",
29-
"eslint-config-prettier": "^6.4.0",
30-
"eslint-plugin-node": "^7.0.1",
31-
"eslint-plugin-prettier": "^3.1.1",
32-
"mocha": "^5.2.0",
33-
"prettier": "^1.14.3"
33+
"@eslint/js": "^9.39.2",
34+
"eslint": "^9.39.2",
35+
"eslint-config-prettier": "^10.1.8",
36+
"eslint-plugin-n": "^17.23.1 ",
37+
"eslint-plugin-prettier": "^5.5.4",
38+
"prettier": "^3.7.4"
3439
},
3540
"engines": {
3641
"node": ">=6.0.0"
37-
}
42+
},
43+
"packageManager": "pnpm@10.26.2+sha512.0e308ff2005fc7410366f154f625f6631ab2b16b1d2e70238444dd6ae9d630a8482d92a451144debc492416896ed16f7b114a86ec68b8404b2443869e68ffda6"
3844
}

0 commit comments

Comments
 (0)