Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions .eslintrc.js

This file was deleted.

22 changes: 13 additions & 9 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,39 @@ Thanks for contributing!
```sh
git clone https://github.com/prettier/prettier-linter-helpers.git
cd prettier-linter-helpers
yarn install
pnpm install
```

## Running the tests
## Running the tests and linters

Run tests:

```sh
yarn run test
pnpm run test
```

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`.
Run linters:

```sh
pnpm run lint
```

## Publishing

- Ensure you are on the master branch locally.
- Ensure you are on the `main` branch locally.
- Update `CHANGELOG.md` and commit.
- Run the following:

```sh
yarn publish
pnpm publish
git push --follow-tags
```

Running `yarn publish` shall:

Running `pnpm publish` shall:
- Bump the version in package.json (asking you for the new version number)
- Create a new commit containing that version bump in package.json
- Create a tag for that commit
- Publish to the npm repository

Running `git push --follow-tags` shall:

- Push the commit and tag to GitHub
20 changes: 20 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2
updates:
- package-ecosystem: npm
directory: /
schedule:
interval: monthly
groups:
dev-dependencies:
dependency-type: development
patterns:
- '*'

- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
groups:
actions:
patterns:
- '*'
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
pull_request: ~
push:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
ci:
name: Lint and Test on Node ${{ matrix.node }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node:
- 24
- 22
- 20

steps:
- name: Checkout Repo
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

- name: Setup pnpm
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0

- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
with:
node-version: ${{ matrix.node }}
cache: pnpm

- name: Install
run: pnpm install --prefer-frozen-lockfile

- name: Test
run: pnpm run test

- name: Lint
run: pnpm run lint
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
package.json
pnpm-lock.yaml
6 changes: 0 additions & 6 deletions dependabot.yml

This file was deleted.

18 changes: 18 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const {defineConfig} = require('eslint/config');
const js = require('@eslint/js');
const eslintPluginN = require('eslint-plugin-n');
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');

module.exports = defineConfig([
{
plugins: {js, n: eslintPluginN},
extends: ['js/recommended', 'n/flat/recommended-script'],
},
eslintPluginPrettierRecommended,
// Internal files
{
files: ['test/**', 'eslint.config.js'],
settings: {node: {version: '20.13.0'}},
rules: {'n/no-unpublished-require': 'off'},
},
]);
29 changes: 29 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Converts invisible characters to a commonly recognizable visible form.
* @param str - The string with invisibles to convert.
* @returns The converted string.
*/
export function showInvisibles(str: string): string;

export interface Difference {
operation: 'insert' | 'delete' | 'replace';
offset: number;
insertText?: string | undefined;
deleteText?: string | undefined;
}

export interface GenerateDifferences {
/**
* Generate results for differences between source code and formatted version.
*
* @param source - The original source.
* @param prettierSource - The Prettier formatted source.
* @returns An array containing { operation, offset, insertText, deleteText }
*/
(source: string, prettierSource: string): Difference[];
INSERT: 'insert';
DELETE: 'delete';
REPLACE: 'replace';
}

export const generateDifferences: GenerateDifferences;
26 changes: 16 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
"Teddy Katz"
],
"main": "index.js",
"types": "index.d.ts",
"license": "MIT",
"scripts": {
"lint": "eslint .",
"test": "npm run lint && mocha",
"format": "yarn run prettier '**/*.{js,json,md,yml}' --write && yarn run lint --fix"
"lint": "eslint . && prettier . --check",
"test": "node --test test/*.test.js",
"format": "eslint . --fix && prettier '**/*.{js,json,md,yml}' --write"
},
"repository": {
"type": "git",
Expand All @@ -21,18 +22,23 @@
"url": "https://github.com/prettier/prettier-linter-helpers/issues"
},
"homepage": "https://github.com/prettier/prettier-linter-helpers#readme",
"files": [
"index.js",
"index.d.ts"
],
"dependencies": {
"fast-diff": "^1.1.2"
},
"devDependencies": {
"eslint": "^5.6.1",
"eslint-config-prettier": "^6.4.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-prettier": "^3.1.1",
"mocha": "^5.2.0",
"prettier": "^1.14.3"
"@eslint/js": "^9.39.2",
"eslint": "^9.39.2",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-n": "^17.23.1 ",
"eslint-plugin-prettier": "^5.5.4",
"prettier": "^3.7.4"
},
"engines": {
"node": ">=6.0.0"
}
},
"packageManager": "pnpm@10.26.2+sha512.0e308ff2005fc7410366f154f625f6631ab2b16b1d2e70238444dd6ae9d630a8482d92a451144debc492416896ed16f7b114a86ec68b8404b2443869e68ffda6"
}
Loading