diff --git a/.changeset/tough-plums-repeat.md b/.changeset/tough-plums-repeat.md new file mode 100644 index 00000000..978eb93a --- /dev/null +++ b/.changeset/tough-plums-repeat.md @@ -0,0 +1,5 @@ +--- +"prettier-eslint": patch +--- + +chore: take `.cjs`, `.cts`, `.mts` into account diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..cc109204 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root=true + +[*] +indent_style=space +indent_size=2 +tab_width=2 +end_of_line=lf +charset=utf-8 +trim_trailing_whitespace=true +insert_final_newline=true diff --git a/.eslintrc.js b/.eslintrc.js index f7fac129..adfc8d43 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,7 +5,7 @@ const config = { 'plugin:node-dependencies/recommended' ], parserOptions: { - ecmaVersion: 2021 + ecmaVersion: 'latest' }, rules: { 'valid-jsdoc': 'off', @@ -20,7 +20,7 @@ const config = { ], 'import/no-import-module-exports': 'off', 'arrow-parens': ['error', 'as-needed'], - quotes: ['error', 'single', { avoidEscape: true }], + quotes: ['error', 'single', { avoidEscape: true }] }, settings: { 'import/ignore': ['node_modules', 'src'] // Using CommonJS in src diff --git a/.gitattributes b/.gitattributes index 391f0a4e..3327ee72 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,3 @@ * text=auto *.js text eol=lf +yarn.lock -diff diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index e948ea76..7cbde355 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -23,14 +23,12 @@ Yes || No **Relevant code or config** -```javascript +```js ``` **What I did:** - - **What happened:** @@ -44,8 +42,4 @@ minimal amount of code possible. **Problem description:** - - **Suggested solution:** - - diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index c25860b1..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,78 +0,0 @@ -version: 2 -updates: -- package-ecosystem: npm - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 - ignore: - - dependency-name: "@typescript-eslint/parser" - versions: - - 4.14.1 - - 4.14.2 - - 4.15.0 - - 4.15.1 - - 4.15.2 - - 4.16.1 - - 4.17.0 - - 4.18.0 - - 4.19.0 - - 4.20.0 - - 4.21.0 - - dependency-name: ajv - versions: - - 7.1.1 - - 7.2.1 - - 7.2.3 - - 8.0.1 - - 8.0.3 - - 8.0.5 - - 8.1.0 - - dependency-name: eslint-config-kentcdodds - versions: - - 17.3.2 - - 17.4.1 - - 17.5.0 - - 17.6.0 - - 17.7.0 - - dependency-name: husky - versions: - - 5.1.2 - - 5.1.3 - - 5.2.0 - - dependency-name: acorn - versions: - - 8.0.5 - - 8.1.0 - - 8.1.1 - - dependency-name: typescript - versions: - - 4.1.3 - - 4.1.4 - - 4.1.5 - - 4.2.2 - - 4.2.3 - - dependency-name: semantic-release - versions: - - 17.3.7 - - 17.3.8 - - 17.3.9 - - 17.4.0 - - 17.4.1 - - dependency-name: vue-eslint-parser - versions: - - 7.4.1 - - 7.5.0 - - 7.6.0 - - dependency-name: jest-cli - versions: - - 26.6.3 - - dependency-name: babel-jest - versions: - - 26.6.3 - - dependency-name: jest - versions: - - 26.6.3 - - dependency-name: pretty-format - versions: - - 26.6.2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25564f41..0f497172 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,12 @@ name: CI -on: [push, pull_request] +on: + - push + - pull_request + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: ci: @@ -8,19 +14,18 @@ jobs: strategy: matrix: - node-version: - - 10 - - 12 - - 14 + node: - 16 - 18 - 20 + - 22 + fail-fast: false steps: - uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + - name: Use Node.js ${{ matrix.node }} + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} @@ -31,6 +36,6 @@ jobs: run: npm start validate - name: Check test coverage - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0ec6233f..c092c294 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,6 +5,15 @@ on: branches: - master +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: write + id-token: write + pull-requests: write + jobs: release: name: Release @@ -13,16 +22,15 @@ jobs: - name: Checkout Repo uses: actions/checkout@v4 with: - # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits fetch-depth: 0 - - name: Setup Node.js 16 - uses: actions/setup-node@v3 + - name: Setup Node.js LTS + uses: actions/setup-node@v4 with: - node-version: 16 + node-version: lts/* - name: Install Dependencies - run: npm install + run: npm i - name: Build run: npm start build @@ -31,10 +39,10 @@ jobs: id: changesets uses: changesets/action@v1 with: - # This expects you to have a script called release which does a build for your packages and calls changeset publish - publish: npm start release commit: 'chore: release prettier-eslint' title: 'chore: release prettier-eslint' + publish: npm start release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_CONFIG_PROVENANCE: true NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 3e1598f5..f191e71c 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -2,18 +2,21 @@ name: Mark stale issues and pull requests on: schedule: - - cron: "0 0 * * *" + - cron: '0 0 * * *' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: stale: - runs-on: ubuntu-latest steps: - - uses: actions/stale@v8 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'Stale issue' - stale-pr-message: 'Stale pull request' - stale-issue-label: 'no-issue-activity' - stale-pr-label: 'no-pr-activity' + - uses: actions/stale@v9 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-issue-message: 'Stale issue' + stale-pr-message: 'Stale pull request' + stale-issue-label: 'no-issue-activity' + stale-pr-label: 'no-pr-activity' diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100755 index a94df36a..00000000 --- a/.husky/pre-commit +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" - -npm start validate diff --git a/.nvmrc b/.nvmrc index cb406c60..5f53e875 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -16.20.2 +v20.19.0 diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index 48b1b40e..00000000 --- a/.prettierrc.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - arrowParens: 'avoid', - singleQuote: true -}; diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 00000000..bde0555c --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,5 @@ +{ + "arrowParens": "avoid", + "singleQuote": true, + "plugins": ["prettier-plugin-pkg", "prettier-plugin-svelte"] +} diff --git a/.simple-git-hooks.json b/.simple-git-hooks.json new file mode 100644 index 00000000..07440aa9 --- /dev/null +++ b/.simple-git-hooks.json @@ -0,0 +1,3 @@ +{ + "pre-commit": "npm start validate" +} diff --git a/README.md b/README.md index a735e077..140143af 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ This allows you to use `eslint` to look for bugs and/or bad practices, and use ## Capturing ESLint messages ```javascript -const {analyze} = require("prettier-eslint"); +const { analyze } = require('prettier-eslint'); const text = 'var x = 0;'; const result = await analyze({ @@ -159,7 +159,7 @@ const result = await analyze({ eslintConfig: { rules: { 'no-var': 'error' } } -}) +}); console.log(result.messages); ``` diff --git a/package-scripts.js b/package-scripts.js index b993df91..655b84cc 100644 --- a/package-scripts.js +++ b/package-scripts.js @@ -52,7 +52,7 @@ module.exports = { release: { description: 'We automate releases with changesets. This should only be run on GitHub Actions', - script: 'changeset publish', + script: series('clean-pkg-json', 'changeset publish'), }, validate: { description: diff --git a/package.json b/package.json index 41edec45..0521c50c 100644 --- a/package.json +++ b/package.json @@ -2,24 +2,36 @@ "name": "prettier-eslint", "version": "16.3.0", "description": "Formats your JavaScript using prettier followed by eslint --fix", + "repository": "git+https://github.com/prettier/prettier-eslint.git", + "homepage": "https://github.com/prettier/prettier-eslint#readme", + "author": "Kent C. Dodds (http://kentcdodds.com/)", + "maintainers": [ + "Simon Fridlund ", + "JounQin (https://www.1stG.me) " + ], + "license": "MIT", + "engines": { + "node": ">=16.10.0" + }, "main": "dist/index.js", "types": "types/index.d.ts", - "scripts": { - "prepare": "husky install", - "start": "nps", - "test": "nps test" - }, "files": [ "dist", "types" ], - "keywords": [], - "author": "Kent C. Dodds (http://kentcdodds.com/)", - "maintainers": [ - "Simon Fridlund ", - "JounQin (https://www.1stG.me) " + "keywords": [ + "eslint", + "formatter", + "linter", + "prettier", + "prettier-eslint" ], - "license": "MIT", + "scripts": { + "preinstall": "npx only-allow npm", + "prepare": "simple-git-hooks", + "start": "nps", + "test": "nps test" + }, "peerDependencies": { "prettier-plugin-svelte": "^3.0.0", "svelte-eslint-parser": "*" @@ -33,49 +45,45 @@ } }, "dependencies": { - "@typescript-eslint/parser": "^6.7.5", - "common-tags": "^1.4.0", - "dlv": "^1.1.0", - "eslint": "^8.7.0", + "@typescript-eslint/parser": "^6.21.0", + "common-tags": "^1.8.2", + "dlv": "^1.1.3", + "eslint": "^8.57.1", "indent-string": "^4.0.0", - "lodash.merge": "^4.6.0", + "lodash.merge": "^4.6.2", "loglevel-colored-level-prefix": "^1.0.0", - "prettier": "^3.0.1", + "prettier": "^3.5.3", "pretty-format": "^29.7.0", "require-relative": "^0.8.7", - "typescript": "^5.2.2", - "vue-eslint-parser": "^9.1.0" + "vue-eslint-parser": "^9.4.3" }, "devDependencies": { - "@babel/cli": "^7.22.9", - "@babel/core": "^7.23.2", - "@babel/preset-env": "^7.22.9", - "@changesets/changelog-github": "^0.4.8", - "@changesets/cli": "^2.26.2", - "@types/eslint": "^8.4.2", - "all-contributors-cli": "^6.7.0", - "eslint-config-kentcdodds": "^20.5.0", - "eslint-plugin-node-dependencies": "^0.11.0", - "husky": "^8.0.1", - "jest": "^29.6.2", - "nps": "^5.7.1", - "nps-utils": "^1.3.0", - "prettier-eslint-cli": "^8.0.0", - "prettier-plugin-svelte": "^3.1.2", - "rimraf": "^5.0.5", + "@babel/cli": "^7.27.0", + "@babel/core": "^7.26.10", + "@babel/preset-env": "^7.26.9", + "@changesets/changelog-github": "^0.5.1", + "@changesets/cli": "^2.29.0", + "@types/eslint": "^8.56.12", + "all-contributors-cli": "^6.26.1", + "clean-pkg-json": "^1.2.1", + "eslint-config-kentcdodds": "^21.0.0", + "eslint-plugin-jest": "^28.11.0", + "eslint-plugin-node-dependencies": "^0.12.0", + "jest": "^29.7.0", + "nps": "^5.10.0", + "nps-utils": "^1.7.0", + "only-allow": "^1.2.1", + "prettier-eslint-cli": "^8.0.1", + "prettier-plugin-pkg": "^0.19.0", + "prettier-plugin-svelte": "^3.3.3", + "rimraf": "^6.0.1", + "simple-git-hooks": "^2.12.1", "strip-indent": "^3.0.0", - "svelte": "^4.2.9", - "svelte-eslint-parser": "^0.33.1" - }, - "engines": { - "node": ">=16.10.0" - }, - "repository": { - "type": "git", - "url": "https://github.com/prettier/prettier-eslint.git" - }, - "bugs": { - "url": "https://github.com/prettier/prettier-eslint/issues" + "svelte": "^4.2.19", + "svelte-eslint-parser": "^0.33.1", + "typescript": "~5.3.3" }, - "homepage": "https://github.com/prettier/prettier-eslint#readme" + "overrides": { + "eslint-plugin-jest": "^28.11.0" + } } diff --git a/src/__tests__/index.js b/src/__tests__/index.js index 4c83d71e..36b16124 100644 --- a/src/__tests__/index.js +++ b/src/__tests__/index.js @@ -5,7 +5,7 @@ import stripIndent from 'strip-indent'; import eslintMock from 'eslint'; import prettierMock from 'prettier'; import loglevelMock from 'loglevel-colored-level-prefix'; -import {format, analyze} from '../'; +import { format, analyze } from '../'; jest.mock('fs'); @@ -197,9 +197,9 @@ const tests = [ title: 'Svelte example', input: { prettierOptions: { - plugins: ['prettier-plugin-svelte'], - overrides: [{ files: '*.svelte', options: { parser: 'svelte' } }] - }, + plugins: ['prettier-plugin-svelte'], + overrides: [{ files: '*.svelte', options: { parser: 'svelte' } }] + }, text: '\n
test
\n', filePath: path.resolve('./test.svelte') }, @@ -276,14 +276,14 @@ test('analyze returns the messages', async () => { eslintConfig: { rules: { 'no-var': 'error' } } - }) + }); expect(result.output).toBe(`${text}\n`); expect(result.messages).toHaveLength(1); const msg = result.messages[0]; expect(msg.ruleId).toBe('no-var'); expect(msg.column).toBe(1); expect(msg.endColumn).toBe(11); -}) +}); test('failure to fix with eslint throws and logs an error', async () => { const { lintText } = eslintMock.mock; diff --git a/src/__tests__/utils.js b/src/__tests__/utils.js index 62f1fa69..2189157d 100644 --- a/src/__tests__/utils.js +++ b/src/__tests__/utils.js @@ -226,13 +226,9 @@ test('if fallbacks are provided, those are preferred over disabled eslint rules' }); test('if fallbacks are provided, those are used if not found in eslint', () => { - const { prettier } = getOptionsForFormatting( - { rules: {} }, - undefined, - { - singleQuote: false - } - ); + const { prettier } = getOptionsForFormatting({ rules: {} }, undefined, { + singleQuote: false + }); expect(prettier).toMatchObject({ singleQuote: false }); }); diff --git a/src/index.js b/src/index.js index 4661b274..eebac326 100644 --- a/src/index.js +++ b/src/index.js @@ -41,7 +41,7 @@ module.exports = format; * @return {Promise} - the formatted string */ async function format(options) { - const {output} = await analyze(options); + const { output } = await analyze(options); return output; } @@ -108,14 +108,18 @@ async function analyze(options) { ); const eslintExtensions = eslintConfig.extensions || [ + '.cjs', + '.cts', '.js', '.jsx', '.ts', '.tsx', '.mjs', + '.mts', '.vue', '.svelte' ]; + const fileExtension = path.extname(filePath || ''); // If we don't get filePath run eslint on text, otherwise only run eslint @@ -155,11 +159,11 @@ async function analyze(options) { function createPrettify(formatOptions, prettierPath) { return async function prettify(param) { - let text = param - let messages = [] + let text = param; + let messages = []; if (typeof param !== 'string') { - text = param.output - messages = param.text + text = param.output; + messages = param.text; } logger.debug('calling prettier on text'); logger.trace( @@ -181,7 +185,7 @@ function createPrettify(formatOptions, prettierPath) { ${indentString(output, 2)} ` ); - return {output, messages}; + return { output, messages }; } catch (error) { logger.error('prettier formatting failed due to a prettier error'); throw error; @@ -249,7 +253,7 @@ function createEslintFix(eslintConfig, eslintPath) { ${indentString(output, 2)} ` ); - return {output, messages}; + return { output, messages }; } catch (error) { logger.error('eslint fix failed due to an eslint error'); throw error; @@ -351,5 +355,5 @@ function getDefaultLogLevel() { // Allow named imports of either `analyze` or `format` from this module, // while leaving `format` in place as the default import: -module.exports.format = format -module.exports.analyze = analyze +module.exports.format = format; +module.exports.analyze = analyze;