Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Jun 19, 2022
1 parent 0e0f879 commit 21f2ea0
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 83 deletions.
7 changes: 4 additions & 3 deletions cspell.json
Expand Up @@ -221,8 +221,8 @@
"neoformat",
"neovim",
"nicolo",
"nocheck",
"nnoremap",
"nocheck",
"nonenumerable",
"Nonspacing",
"noopener",
Expand Down Expand Up @@ -271,9 +271,9 @@
"Pschera",
"quasis",
"Raghuvir",
"raquo",
"Rasmus",
"Rattray",
"raquo",
"rattrayalex",
"readline",
"readlines",
Expand All @@ -283,6 +283,7 @@
"refmt",
"regexes",
"Reimplement",
"require",
"rhengles",
"ribaudo",
"Roadmap",
Expand All @@ -292,8 +293,8 @@
"sandhose",
"Sapegin",
"sbdchd",
"sdbm",
"scandir",
"sdbm",
"Serializers",
"setlocal",
"setq",
Expand Down
2 changes: 1 addition & 1 deletion 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 */

Expand Down
10 changes: 4 additions & 6 deletions 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
Expand All @@ -16,4 +14,4 @@ function findCacheFile() {
return cacheFilePath;
}

module.exports = findCacheFile;
export default findCacheFile;
13 changes: 5 additions & 8 deletions 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;
Expand Down Expand Up @@ -93,4 +90,4 @@ class FormatResultsCache {
}
}

module.exports = FormatResultsCache;
export default FormatResultsCache;
6 changes: 1 addition & 5 deletions src/cli/format.js
Expand Up @@ -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);
Expand Down
10 changes: 4 additions & 6 deletions 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);

Expand Down Expand Up @@ -77,5 +74,6 @@ export {
printToScreen,
groupBy,
pick,
createHash, statSafe
createHash,
statSafe,
};
2 changes: 1 addition & 1 deletion src/language-js/languages.evaluate.js
Expand Up @@ -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"],
Expand Down
5 changes: 2 additions & 3 deletions 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;
Expand All @@ -9,4 +8,4 @@ function throwSyntaxError(node, message) {
});
}

module.exports = throwSyntaxError;
export default throwSyntaxError;
2 changes: 1 addition & 1 deletion tests/format/angular/shorthand/jsfmt.spec.js
@@ -1 +1 @@
run_spec(__dirname, ["angular"]);
run_spec(import.meta, ["angular"]);
26 changes: 24 additions & 2 deletions tests/integration/__tests__/__snapshots__/support-info.js.snap
Expand Up @@ -375,6 +375,7 @@ exports[`CLI --support-info (stdout) 1`] = `
"color": "#e34c26",
"extensions": [
".html",
".hta",
".htm",
".html.hl",
".inc",
Expand Down Expand Up @@ -406,10 +407,13 @@ exports[`CLI --support-info (stdout) 1`] = `
".frag",
".gs",
".jake",
".javascript",
".jsb",
".jscad",
".jsfl",
".jslib",
".jsm",
".jspre",
".jss",
".mjs",
".njs",
Expand Down Expand Up @@ -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",
Expand All @@ -474,8 +482,11 @@ exports[`CLI --support-info (stdout) 1`] = `
],
"filenames": [
".arcconfig",
".auto-changelog",
".c8rc",
".htmlhintrc",
".imgbotconfig",
".nycrc",
".tern-config",
".tern-project",
".watchmanconfig",
Expand All @@ -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",
Expand All @@ -514,6 +527,7 @@ exports[`CLI --support-info (stdout) 1`] = `
],
"filenames": [
".babelrc",
".devcontainer.json",
".eslintrc.json",
".jscsrc",
".jshintrc",
Expand All @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -587,6 +604,7 @@ exports[`CLI --support-info (stdout) 1`] = `
},
{
"aceMode": "less",
"aliases": ["less-css"],
"codemirrorMimeType": "text/css",
"codemirrorMode": "css",
"color": "#1d365d",
Expand Down Expand Up @@ -623,6 +641,7 @@ exports[`CLI --support-info (stdout) 1`] = `
"color": "#083fa1",
"extensions": [
".md",
".livemd",
".markdown",
".mdown",
".mdwn",
Expand Down Expand Up @@ -662,6 +681,7 @@ exports[`CLI --support-info (stdout) 1`] = `
},
{
"aceMode": "text",
"color": "#dc3a0c",
"extensions": [".pcss", ".postcss"],
"group": "CSS",
"linguistLanguageId": 262764437,
Expand Down Expand Up @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -750,6 +771,7 @@ exports[`CLI --support-info (stdout) 1`] = `
".clang-format",
".clang-tidy",
".gemrc",
"CITATION.cff",
"glide.lock",
".prettierrc",
".stylelintrc"
Expand Down
15 changes: 6 additions & 9 deletions 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", () => {
Expand Down
3 changes: 0 additions & 3 deletions vendors/sdbm.d.ts

This file was deleted.

35 changes: 0 additions & 35 deletions vendors/sdbm.js

This file was deleted.

0 comments on commit 21f2ea0

Please sign in to comment.