diff --git a/cspell.json b/cspell.json index cd85816a1bd1..a179891de27e 100644 --- a/cspell.json +++ b/cspell.json @@ -221,8 +221,8 @@ "neoformat", "neovim", "nicolo", - "nocheck", "nnoremap", + "nocheck", "nonenumerable", "Nonspacing", "noopener", @@ -271,9 +271,9 @@ "Pschera", "quasis", "Raghuvir", + "raquo", "Rasmus", "Rattray", - "raquo", "rattrayalex", "readline", "readlines", @@ -283,6 +283,7 @@ "refmt", "regexes", "Reimplement", + "require", "rhengles", "ribaudo", "Roadmap", @@ -292,8 +293,8 @@ "sandhose", "Sapegin", "sbdchd", - "sdbm", "scandir", + "sdbm", "Serializers", "setlocal", "setq", diff --git a/src/cli/expand-patterns.js b/src/cli/expand-patterns.js index d3ef49ed11e2..4bed26f00438 100644 --- a/src/cli/expand-patterns.js +++ b/src/cli/expand-patterns.js @@ -1,6 +1,6 @@ import path from "node:path"; import fastGlob from "fast-glob"; -import {statSafe} from "./utils.js" +import { statSafe } from "./utils.js"; /** @typedef {import('./context').Context} Context */ diff --git a/src/cli/find-cache-file.js b/src/cli/find-cache-file.js index c8960ead4788..c139c3c4c797 100644 --- a/src/cli/find-cache-file.js +++ b/src/cli/find-cache-file.js @@ -1,8 +1,6 @@ -"use strict"; - -const os = require("os"); -const path = require("path"); -const findCacheDir = require("find-cache-dir"); +import os from "node:os"; +import path from "node:path"; +import findCacheDir from "find-cache-dir"; /** * Find default cache file (`./node_modules/.cache/prettier/.prettier-cache`) using https://github.com/avajs/find-cache-dir @@ -16,4 +14,4 @@ function findCacheFile() { return cacheFilePath; } -module.exports = findCacheFile; +export default findCacheFile; diff --git a/src/cli/format-results-cache.js b/src/cli/format-results-cache.js index 3dfb79d16535..595b3ec08d78 100644 --- a/src/cli/format-results-cache.js +++ b/src/cli/format-results-cache.js @@ -1,13 +1,10 @@ -"use strict"; - // Inspired by LintResultsCache from ESLint // https://github.com/eslint/eslint/blob/c2d0a830754b6099a3325e6d3348c3ba983a677a/lib/cli-engine/lint-result-cache.js -const fileEntryCache = require("file-entry-cache"); -const stringify = require("fast-json-stable-stringify"); -// eslint-disable-next-line no-restricted-modules -const { version: prettierVersion } = require("../index.js"); -const { createHash } = require("./utils.js"); +import fileEntryCache from "file-entry-cache"; +import stringify from "fast-json-stable-stringify"; +import { version as prettierVersion } from "../index.js"; +import { createHash } from "./utils.js"; const optionsHashCache = new WeakMap(); const nodeVersion = process && process.version; @@ -93,4 +90,4 @@ class FormatResultsCache { } } -module.exports = FormatResultsCache; +export default FormatResultsCache; diff --git a/src/cli/format.js b/src/cli/format.js index b3b440dafc86..0c45df7c6c29 100644 --- a/src/cli/format.js +++ b/src/cli/format.js @@ -400,15 +400,11 @@ async function formatFiles(context) { let output; try { -<<<<<<< HEAD - result = await format(context, input, options); -======= if (isCacheExists) { result = { formatted: input }; } else { - result = format(context, input, options); + result = await format(context, input, options); } ->>>>>>> main output = result.formatted; } catch (error) { handleError(context, filename, error, printedFilename); diff --git a/src/cli/utils.js b/src/cli/utils.js index b20fa1d59477..56032f9d2469 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -1,12 +1,9 @@ +import { promises as fs } from "node:fs"; +import sdbm from "sdbm"; import { __internal as sharedWithCli } from "../index.js"; const { arrayify, getLast, isNonEmptyArray, partition } = sharedWithCli.utils; -const { promises: fs } = require("fs"); - -// eslint-disable-next-line no-restricted-modules -const { default: sdbm } = require("../../vendors/sdbm.js"); - // eslint-disable-next-line no-console const printToScreen = console.log.bind(console); @@ -77,5 +74,6 @@ export { printToScreen, groupBy, pick, -createHash, statSafe + createHash, + statSafe, }; diff --git a/src/language-js/languages.evaluate.js b/src/language-js/languages.evaluate.js index 053e0f816eb0..710e91972678 100644 --- a/src/language-js/languages.evaluate.js +++ b/src/language-js/languages.evaluate.js @@ -60,7 +60,7 @@ const languages = [ codemirrorMimeType: "text/jsx", color: undefined, })), - createLanguage(linguistLanguages.TypeScript, (data) => ({ + createLanguage(linguistLanguages.TypeScript, () => ({ since: "1.4.0", parsers: ["typescript", "babel-ts"], vscodeLanguageIds: ["typescript"], diff --git a/src/language-js/parse/postprocess/throw-syntax-error.js b/src/language-js/parse/postprocess/throw-syntax-error.js index 0505aba379c4..f06572821dce 100644 --- a/src/language-js/parse/postprocess/throw-syntax-error.js +++ b/src/language-js/parse/postprocess/throw-syntax-error.js @@ -1,5 +1,4 @@ -"use strict"; -const createError = require("../../../common/parser-create-error.js"); +import createError from "../../../common/parser-create-error.js"; function throwSyntaxError(node, message) { const { start, end } = node.loc; @@ -9,4 +8,4 @@ function throwSyntaxError(node, message) { }); } -module.exports = throwSyntaxError; +export default throwSyntaxError; diff --git a/tests/format/angular/shorthand/jsfmt.spec.js b/tests/format/angular/shorthand/jsfmt.spec.js index b802ad8670c5..c67dba8b412e 100644 --- a/tests/format/angular/shorthand/jsfmt.spec.js +++ b/tests/format/angular/shorthand/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["angular"]); +run_spec(import.meta, ["angular"]); diff --git a/tests/integration/__tests__/__snapshots__/support-info.js.snap b/tests/integration/__tests__/__snapshots__/support-info.js.snap index f527b939a5d2..94289e4fb8bf 100644 --- a/tests/integration/__tests__/__snapshots__/support-info.js.snap +++ b/tests/integration/__tests__/__snapshots__/support-info.js.snap @@ -375,6 +375,7 @@ exports[`CLI --support-info (stdout) 1`] = ` "color": "#e34c26", "extensions": [ ".html", + ".hta", ".htm", ".html.hl", ".inc", @@ -406,10 +407,13 @@ exports[`CLI --support-info (stdout) 1`] = ` ".frag", ".gs", ".jake", + ".javascript", ".jsb", ".jscad", ".jsfl", + ".jslib", ".jsm", + ".jspre", ".jss", ".mjs", ".njs", @@ -453,10 +457,14 @@ exports[`CLI --support-info (stdout) 1`] = ` }, { "aceMode": "json", + "aliases": ["geojson", "jsonl", "topojson"], "codemirrorMimeType": "application/json", "codemirrorMode": "javascript", + "color": "#292929", "extensions": [ ".json", + ".4DForm", + ".4DProject", ".avsc", ".geojson", ".gltf", @@ -474,8 +482,11 @@ exports[`CLI --support-info (stdout) 1`] = ` ], "filenames": [ ".arcconfig", + ".auto-changelog", + ".c8rc", ".htmlhintrc", ".imgbotconfig", + ".nycrc", ".tern-config", ".tern-project", ".watchmanconfig", @@ -496,8 +507,10 @@ exports[`CLI --support-info (stdout) 1`] = ` "aliases": ["jsonc"], "codemirrorMimeType": "text/javascript", "codemirrorMode": "javascript", + "color": "#292929", "extensions": [ ".jsonc", + ".code-snippets", ".sublime-build", ".sublime-commands", ".sublime-completions", @@ -514,6 +527,7 @@ exports[`CLI --support-info (stdout) 1`] = ` ], "filenames": [ ".babelrc", + ".devcontainer.json", ".eslintrc.json", ".jscsrc", ".jshintrc", @@ -538,8 +552,10 @@ exports[`CLI --support-info (stdout) 1`] = ` }, { "aceMode": "json", + "aliases": ["geojson", "jsonl", "topojson"], "codemirrorMimeType": "application/json", "codemirrorMode": "javascript", + "color": "#292929", "extensions": [".importmap"], "filenames": ["package.json", "package-lock.json", "composer.json"], "linguistLanguageId": 174, @@ -554,6 +570,7 @@ exports[`CLI --support-info (stdout) 1`] = ` "aceMode": "javascript", "codemirrorMimeType": "application/json", "codemirrorMode": "javascript", + "color": "#267CB9", "extensions": [".json5"], "linguistLanguageId": 175, "name": "JSON5", @@ -587,6 +604,7 @@ exports[`CLI --support-info (stdout) 1`] = ` }, { "aceMode": "less", + "aliases": ["less-css"], "codemirrorMimeType": "text/css", "codemirrorMode": "css", "color": "#1d365d", @@ -623,6 +641,7 @@ exports[`CLI --support-info (stdout) 1`] = ` "color": "#083fa1", "extensions": [ ".md", + ".livemd", ".markdown", ".mdown", ".mdwn", @@ -662,6 +681,7 @@ exports[`CLI --support-info (stdout) 1`] = ` }, { "aceMode": "text", + "color": "#dc3a0c", "extensions": [".pcss", ".postcss"], "group": "CSS", "linguistLanguageId": 262764437, @@ -690,6 +710,7 @@ exports[`CLI --support-info (stdout) 1`] = ` "aceMode": "javascript", "codemirrorMimeType": "text/jsx", "codemirrorMode": "jsx", + "color": "#3178c6", "extensions": [".tsx"], "group": "TypeScript", "linguistLanguageId": 94901924, @@ -705,8 +726,8 @@ exports[`CLI --support-info (stdout) 1`] = ` "aliases": ["ts"], "codemirrorMimeType": "application/typescript", "codemirrorMode": "javascript", - "color": "#2b7489", - "extensions": [".ts", ".mts", ".cts"], + "color": "#3178c6", + "extensions": [".ts", ".cts", ".mts"], "interpreters": ["deno", "ts-node"], "linguistLanguageId": 378, "name": "TypeScript", @@ -750,6 +771,7 @@ exports[`CLI --support-info (stdout) 1`] = ` ".clang-format", ".clang-tidy", ".gemrc", + "CITATION.cff", "glide.lock", ".prettierrc", ".stylelintrc" diff --git a/tests/integration/__tests__/cache.js b/tests/integration/__tests__/cache.js index 863cd29017d9..fd563c874f9c 100644 --- a/tests/integration/__tests__/cache.js +++ b/tests/integration/__tests__/cache.js @@ -1,14 +1,11 @@ -"use strict"; - -const path = require("path"); -const { promises: fs } = require("fs"); -const rimraf = require("rimraf"); -const { default: stripAnsi } = require("../../../vendors/strip-ansi.js"); - -const runPrettier = require("../run-prettier.js"); +import path from "node:path"; +import { promises as fs } from "node:fs"; +import { fileURLToPath } from "node:url"; +import rimraf from "rimraf"; +import stripAnsi from "strip-ansi"; function resolveDir(dir) { - return path.join(__dirname, "..", dir); + return fileURLToPath(new URL(`../${dir}/`, import.meta.url)); } describe("--cache option", () => { diff --git a/vendors/sdbm.d.ts b/vendors/sdbm.d.ts deleted file mode 100644 index 812356628a7f..000000000000 --- a/vendors/sdbm.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -// This file is generated automatically. -export {default} from "sdbm"; -export * from "sdbm"; diff --git a/vendors/sdbm.js b/vendors/sdbm.js deleted file mode 100644 index d867062988b5..000000000000 --- a/vendors/sdbm.js +++ /dev/null @@ -1,35 +0,0 @@ -// @ts-nocheck -// This file is generated automatically -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// node_modules/sdbm/index.js -var sdbm_exports = {}; -__export(sdbm_exports, { - default: () => sdbm -}); -module.exports = __toCommonJS(sdbm_exports); -function sdbm(string) { - let hash = 0; - for (let i = 0; i < string.length; i++) { - hash = string.charCodeAt(i) + (hash << 6) + (hash << 16) - hash; - } - return hash >>> 0; -} -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = {});