prettier-plugin-toml
Advanced tools
Comparing version 0.4.0 to 1.0.0
# prettier-plugin-toml | ||
## 1.0.0 | ||
### Major Changes | ||
- [#67](https://github.com/un-ts/toml-tools/pull/67) [`8daff91`](https://github.com/un-ts/toml-tools/commit/8daff91c3cce09e3c8bb3501be8b9be39e796f63) Thanks [@JounQin](https://github.com/JounQin)! - feat!: migrate to pure ESM and prettier v3 | ||
### Patch Changes | ||
- Updated dependencies [[`8daff91`](https://github.com/un-ts/toml-tools/commit/8daff91c3cce09e3c8bb3501be8b9be39e796f63)]: | ||
- @toml-tools/lexer@1.0.0 | ||
- @toml-tools/parser@1.0.0 | ||
## 0.4.0 | ||
@@ -4,0 +16,0 @@ |
@@ -1,4 +0,4 @@ | ||
const { locStart, locEnd } = require("./loc"); | ||
const { parse } = require("@toml-tools/parser"); | ||
const { print } = require("./printer"); | ||
import { locStart, locEnd } from "./loc.js"; | ||
import { parse } from "@toml-tools/parser"; | ||
import { print } from "./printer.js"; | ||
@@ -39,3 +39,3 @@ // https://prettier.io/docs/en/plugins.html#languages | ||
module.exports = { | ||
export { | ||
languages, | ||
@@ -42,0 +42,0 @@ parsers, |
@@ -9,5 +9,2 @@ function locStart(cstNode) { | ||
module.exports = { | ||
locStart, | ||
locEnd, | ||
}; | ||
export { locStart, locEnd }; |
@@ -25,3 +25,3 @@ function trimComment(commentText) { | ||
throw Error( | ||
`Expecting single key CST ctx but found: <${ctxKeys.length}> keys` | ||
`Expecting single key CST ctx but found: <${ctxKeys.length}> keys`, | ||
); | ||
@@ -34,3 +34,3 @@ } | ||
throw Error( | ||
`Expecting single item in CST ctx key but found: <${singleElementValues.length}> items` | ||
`Expecting single item in CST ctx key but found: <${singleElementValues.length}> items`, | ||
); | ||
@@ -75,3 +75,3 @@ } | ||
module.exports = { | ||
export { | ||
trimComment, | ||
@@ -78,0 +78,0 @@ canUnquote, |
@@ -1,5 +0,5 @@ | ||
const { BaseTomlCstVisitor } = require("@toml-tools/parser"); | ||
const { tokensDictionary: t } = require("@toml-tools/lexer"); | ||
const { | ||
import { BaseTomlCstVisitor } from "@toml-tools/parser"; | ||
import { tokensDictionary as t } from "@toml-tools/lexer"; | ||
import { doc, version } from "prettier"; | ||
import { | ||
trimComment, | ||
@@ -10,6 +10,6 @@ collectComments, | ||
getSingle, | ||
} = require("./printer-utils"); | ||
const { concat, join, line, hardline, softline, ifBreak, indent, group } = | ||
require("prettier").doc.builders; | ||
} from "./printer-utils.js"; | ||
const { join, line, hardline, softline, ifBreak, indent, group } = doc.builders; | ||
class TomlBeautifierVisitor extends BaseTomlCstVisitor { | ||
@@ -54,3 +54,3 @@ constructor() { | ||
if (ctx.expression === undefined) { | ||
return concat([line]); | ||
return [line]; | ||
} | ||
@@ -108,13 +108,10 @@ | ||
const docGroupsInnerNewlines = docGroups.map((currGroup) => | ||
join(line, currGroup) | ||
join(line, currGroup), | ||
); | ||
const docGroupsOuterNewlines = join( | ||
concat([line, line]), | ||
docGroupsInnerNewlines | ||
); | ||
return concat([ | ||
const docGroupsOuterNewlines = join([line, line], docGroupsInnerNewlines); | ||
return [ | ||
docGroupsOuterNewlines, | ||
// Terminating newline | ||
line, | ||
]); | ||
]; | ||
} | ||
@@ -127,3 +124,3 @@ | ||
const commentText = trimComment(ctx.Comment[0].image); | ||
keyValDoc = concat([keyValDoc, " " + commentText]); | ||
keyValDoc = [keyValDoc, " " + commentText]; | ||
} | ||
@@ -135,3 +132,3 @@ return keyValDoc; | ||
const commentText = trimComment(ctx.Comment[0].image); | ||
tableDoc = concat([tableDoc, " " + commentText]); | ||
tableDoc = [tableDoc, " " + commentText]; | ||
} | ||
@@ -147,3 +144,3 @@ return tableDoc; | ||
const valueDoc = this.visit(ctx.val); | ||
return concat([keyDoc, " = ", valueDoc]); | ||
return [keyDoc, " = ", valueDoc]; | ||
} | ||
@@ -171,16 +168,7 @@ | ||
const postComments = collectComments(ctx.commentNewline); | ||
const commentsDocs = concat( | ||
postComments.map((commentTok) => { | ||
const trimmedCommentText = trimComment(commentTok.image); | ||
return concat([hardline, trimmedCommentText]); | ||
}) | ||
); | ||
return group( | ||
concat([ | ||
"[", | ||
indent(concat([arrayValuesDocs, commentsDocs])), | ||
softline, | ||
"]", | ||
]) | ||
); | ||
const commentsDocs = postComments.map((commentTok) => { | ||
const trimmedCommentText = trimComment(commentTok.image); | ||
return [hardline, trimmedCommentText]; | ||
}); | ||
return group(["[", indent([arrayValuesDocs, commentsDocs]), softline, "]"]); | ||
} | ||
@@ -228,3 +216,3 @@ | ||
// a hardline is used to ensure a lineBreak after the comment | ||
itemsDoc.push(concat([valDoc, potentialComma, comment, hardline])); | ||
itemsDoc.push([valDoc, potentialComma, comment, hardline]); | ||
} | ||
@@ -237,4 +225,4 @@ // no comment on the same line | ||
ifBreak(",", "") | ||
: concat([potentialComma, line]); | ||
itemsDoc.push(concat([valDoc, optionalCommaLineBreak])); | ||
: [potentialComma, line]; | ||
itemsDoc.push([valDoc, optionalCommaLineBreak]); | ||
} | ||
@@ -244,3 +232,3 @@ } | ||
else { | ||
itemsDoc.push(concat([valDoc])); | ||
itemsDoc.push([valDoc]); | ||
} | ||
@@ -251,3 +239,3 @@ } | ||
const trimmedComment = trimComment(cstItem.image); | ||
itemsDoc.push(concat([trimmedComment, hardline])); | ||
itemsDoc.push([trimmedComment, hardline]); | ||
} else { | ||
@@ -257,3 +245,3 @@ throw Error("non exhaustive match"); | ||
} | ||
return concat([softline, concat(itemsDoc)]); | ||
return [softline, itemsDoc]; | ||
} | ||
@@ -265,3 +253,3 @@ | ||
: ""; | ||
return group(concat(["{ ", inlineTableKeyValsDocs, " }"])); | ||
return group(["{ ", inlineTableKeyValsDocs, " }"]); | ||
} | ||
@@ -280,3 +268,3 @@ | ||
const keyDoc = this.visit(ctx.key); | ||
return concat(["[", keyDoc, "]"], line); | ||
return ["[", keyDoc, "]"]; | ||
} | ||
@@ -286,3 +274,3 @@ | ||
const keyDoc = this.visit(ctx.key); | ||
return concat(["[[", keyDoc, "]]"], line); | ||
return ["[[", keyDoc, "]]"]; | ||
} | ||
@@ -307,4 +295,2 @@ | ||
module.exports = { | ||
print, | ||
}; | ||
export { print }; |
{ | ||
"name": "prettier-plugin-toml", | ||
"version": "0.4.0", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"description": "TOML Prettier Plugin", | ||
"repository": "https://github.com/un-ts/toml-tools/tree/master/packages/prettier-plugin-toml", | ||
"license": "MIT", | ||
"main": "lib/api.js", | ||
"exports": { | ||
".": "./lib/api.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"keywords": [ | ||
@@ -11,15 +19,12 @@ "toml", | ||
], | ||
"main": "lib/api.js", | ||
"repository": "https://github.com/un-ts/toml-tools/tree/master/packages/prettier-plugin-toml", | ||
"license": "MIT", | ||
"scripts": { | ||
"test": "mocha ./test/**/*spec.js" | ||
}, | ||
"peerDependencies": { | ||
"prettier": "^1.16.0 || ^2.0.0" | ||
"prettier": "^3.0.0" | ||
}, | ||
"dependencies": { | ||
"@toml-tools/lexer": "^0.4.0", | ||
"@toml-tools/parser": "^0.4.0" | ||
"@toml-tools/lexer": "^1.0.0", | ||
"@toml-tools/parser": "^1.0.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha ./test/**/*spec.js" | ||
}, | ||
"publishConfig": { | ||
@@ -26,0 +31,0 @@ "access": "public" |
@@ -0,3 +1,5 @@ | ||
import { testSample } from "../test-utils.js"; | ||
describe("prettier-toml", () => { | ||
require("../test-utils").testSample(__dirname); | ||
testSample(import.meta); | ||
}); |
@@ -0,3 +1,5 @@ | ||
import { testSample } from "../test-utils.js"; | ||
describe("prettier-toml", () => { | ||
require("../test-utils").testSample(__dirname); | ||
testSample(import.meta); | ||
}); |
@@ -0,3 +1,5 @@ | ||
import { testSample } from "../test-utils.js"; | ||
describe("prettier-toml", () => { | ||
require("../test-utils").testSample(__dirname); | ||
testSample(import.meta); | ||
}); |
@@ -0,3 +1,5 @@ | ||
import { testSample } from "../test-utils.js"; | ||
describe("prettier-toml", () => { | ||
require("../test-utils").testSample(__dirname); | ||
testSample(import.meta); | ||
}); |
@@ -0,3 +1,5 @@ | ||
import { testSample } from "../test-utils.js"; | ||
describe("prettier-toml", () => { | ||
require("../test-utils").testSample(__dirname); | ||
testSample(import.meta); | ||
}); |
@@ -0,3 +1,5 @@ | ||
import { testSample } from "../test-utils.js"; | ||
describe("prettier-toml", () => { | ||
require("../test-utils").testSample(__dirname); | ||
testSample(import.meta); | ||
}); |
@@ -1,12 +0,17 @@ | ||
const prettier = require("prettier"); | ||
const { expect } = require("chai"); | ||
const { readFileSync } = require("fs"); | ||
const { resolve, relative } = require("path"); | ||
import prettier from "prettier"; | ||
import { expect } from "chai"; | ||
import { readFileSync } from "fs"; | ||
import { dirname, resolve, relative } from "path"; | ||
import { fileURLToPath } from "url"; | ||
const pluginPath = resolve(__dirname, "../"); | ||
function testSample(testFolder, exclusive) { | ||
const _dirname = dirname(fileURLToPath(import.meta.url)); | ||
const pluginPath = "prettier-plugin-toml"; | ||
function testSample(importMeta, exclusive) { | ||
const testFolder = resolve(fileURLToPath(importMeta.url), ".."); | ||
const itOrItOnly = exclusive ? it.only : it; | ||
const inputPath = resolve(testFolder, "_input.toml"); | ||
const expectedPath = resolve(testFolder, "_output.toml"); | ||
const relativeInputPath = relative(__dirname, inputPath); | ||
const relativeInputPath = relative(_dirname, inputPath); | ||
@@ -21,4 +26,4 @@ let inputContents; | ||
itOrItOnly(`can format <${relativeInputPath}>`, () => { | ||
const actual = prettier.format(inputContents, { | ||
itOrItOnly(`can format <${relativeInputPath}>`, async () => { | ||
const actual = await prettier.format(inputContents, { | ||
parser: "toml", | ||
@@ -29,8 +34,8 @@ plugins: [pluginPath], | ||
expect(normalizeNewlines(actual)).to.equal( | ||
normalizeNewlines(expectedContents) | ||
normalizeNewlines(expectedContents), | ||
); | ||
}); | ||
it(`Performs a stable formatting for <${relativeInputPath}>`, () => { | ||
const onePass = prettier.format(inputContents, { | ||
it(`Performs a stable formatting for <${relativeInputPath}>`, async () => { | ||
const onePass = await prettier.format(inputContents, { | ||
parser: "toml", | ||
@@ -40,3 +45,3 @@ plugins: [pluginPath], | ||
const secondPass = prettier.format(onePass, { | ||
const secondPass = await prettier.format(onePass, { | ||
parser: "toml", | ||
@@ -56,4 +61,2 @@ plugins: [pluginPath], | ||
module.exports = { | ||
testSample, | ||
}; | ||
export { testSample }; |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
20841
1
Yes
437
+ Added@chevrotain/cst-dts-gen@11.0.3(transitive)
+ Added@chevrotain/gast@11.0.3(transitive)
+ Added@chevrotain/regexp-to-ast@11.0.3(transitive)
+ Added@chevrotain/types@11.0.3(transitive)
+ Added@chevrotain/utils@11.0.3(transitive)
+ Added@toml-tools/lexer@1.0.1(transitive)
+ Added@toml-tools/parser@1.0.1(transitive)
+ Addedchevrotain@11.0.3(transitive)
+ Addedlodash-es@4.17.21(transitive)
+ Addedprettier@3.4.2(transitive)
- Removed@chevrotain/cst-dts-gen@10.5.0(transitive)
- Removed@chevrotain/gast@10.5.0(transitive)
- Removed@chevrotain/types@10.5.0(transitive)
- Removed@chevrotain/utils@10.5.0(transitive)
- Removed@toml-tools/lexer@0.4.0(transitive)
- Removed@toml-tools/parser@0.4.0(transitive)
- Removedchevrotain@10.5.0(transitive)
- Removedlodash@4.17.21(transitive)
- Removedprettier@2.8.8(transitive)
- Removedregexp-to-ast@0.5.0(transitive)
Updated@toml-tools/lexer@^1.0.0
Updated@toml-tools/parser@^1.0.0