Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: prettier/plugin-xml
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.2.0
Choose a base ref
...
head repository: prettier/plugin-xml
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.2.1
Choose a head ref

Commits on Aug 14, 2023

  1. chore(deps-dev): bump eslint from 8.46.0 to 8.47.0

    Bumps [eslint](https://github.com/eslint/eslint) from 8.46.0 to 8.47.0.
    - [Release notes](https://github.com/eslint/eslint/releases)
    - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
    - [Commits](eslint/eslint@v8.46.0...v8.47.0)
    
    ---
    updated-dependencies:
    - dependency-name: eslint
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Aug 14, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    297f1b8 View commit details
  2. Merge pull request #706 from prettier/dependabot/npm_and_yarn/eslint-…

    …8.47.0
    
    chore(deps-dev): bump eslint from 8.46.0 to 8.47.0
    github-actions[bot] authored Aug 14, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c4f3453 View commit details
  3. chore(deps-dev): bump lint-staged from 13.2.3 to 14.0.0

    Bumps [lint-staged](https://github.com/okonet/lint-staged) from 13.2.3 to 14.0.0.
    - [Release notes](https://github.com/okonet/lint-staged/releases)
    - [Commits](lint-staged/lint-staged@v13.2.3...v14.0.0)
    
    ---
    updated-dependencies:
    - dependency-name: lint-staged
      dependency-type: direct:development
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Aug 14, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a85e632 View commit details
  4. Merge pull request #707 from prettier/dependabot/npm_and_yarn/lint-st…

    …aged-14.0.0
    
    chore(deps-dev): bump lint-staged from 13.2.3 to 14.0.0
    github-actions[bot] authored Aug 14, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c982f73 View commit details

Commits on Aug 16, 2023

  1. chore(deps-dev): bump prettier from 3.0.1 to 3.0.2

    Bumps [prettier](https://github.com/prettier/prettier) from 3.0.1 to 3.0.2.
    - [Release notes](https://github.com/prettier/prettier/releases)
    - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
    - [Commits](prettier/prettier@3.0.1...3.0.2)
    
    ---
    updated-dependencies:
    - dependency-name: prettier
      dependency-type: direct:development
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Aug 16, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    58987f3 View commit details
  2. Merge pull request #708 from prettier/dependabot/npm_and_yarn/prettie…

    …r-3.0.2
    
    chore(deps-dev): bump prettier from 3.0.1 to 3.0.2
    github-actions[bot] authored Aug 16, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c61a8cf View commit details

Commits on Aug 22, 2023

  1. chore(deps-dev): bump lint-staged from 14.0.0 to 14.0.1

    Bumps [lint-staged](https://github.com/okonet/lint-staged) from 14.0.0 to 14.0.1.
    - [Release notes](https://github.com/okonet/lint-staged/releases)
    - [Commits](lint-staged/lint-staged@v14.0.0...v14.0.1)
    
    ---
    updated-dependencies:
    - dependency-name: lint-staged
      dependency-type: direct:development
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Aug 22, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e4b293f View commit details
  2. chore(deps-dev): bump jest from 29.6.2 to 29.6.3

    Bumps [jest](https://github.com/jestjs/jest/tree/HEAD/packages/jest) from 29.6.2 to 29.6.3.
    - [Release notes](https://github.com/jestjs/jest/releases)
    - [Changelog](https://github.com/jestjs/jest/blob/main/CHANGELOG.md)
    - [Commits](https://github.com/jestjs/jest/commits/v29.6.3/packages/jest)
    
    ---
    updated-dependencies:
    - dependency-name: jest
      dependency-type: direct:development
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Aug 22, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3684e51 View commit details
  3. Merge pull request #710 from prettier/dependabot/npm_and_yarn/lint-st…

    …aged-14.0.1
    
    chore(deps-dev): bump lint-staged from 14.0.0 to 14.0.1
    github-actions[bot] authored Aug 22, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fc4ca82 View commit details
  4. Merge pull request #711 from prettier/dependabot/npm_and_yarn/jest-29…

    ….6.3
    
    chore(deps-dev): bump jest from 29.6.2 to 29.6.3
    github-actions[bot] authored Aug 22, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bab8ad9 View commit details

Commits on Aug 25, 2023

  1. chore(deps-dev): bump jest from 29.6.3 to 29.6.4

    Bumps [jest](https://github.com/jestjs/jest/tree/HEAD/packages/jest) from 29.6.3 to 29.6.4.
    - [Release notes](https://github.com/jestjs/jest/releases)
    - [Changelog](https://github.com/jestjs/jest/blob/main/CHANGELOG.md)
    - [Commits](https://github.com/jestjs/jest/commits/v29.6.4/packages/jest)
    
    ---
    updated-dependencies:
    - dependency-name: jest
      dependency-type: direct:development
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Aug 25, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b20807b View commit details
  2. Merge pull request #712 from prettier/dependabot/npm_and_yarn/jest-29…

    ….6.4
    
    chore(deps-dev): bump jest from 29.6.3 to 29.6.4
    github-actions[bot] authored Aug 25, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    30fc258 View commit details

Commits on Aug 28, 2023

  1. chore(deps-dev): bump eslint from 8.47.0 to 8.48.0

    Bumps [eslint](https://github.com/eslint/eslint) from 8.47.0 to 8.48.0.
    - [Release notes](https://github.com/eslint/eslint/releases)
    - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
    - [Commits](eslint/eslint@v8.47.0...v8.48.0)
    
    ---
    updated-dependencies:
    - dependency-name: eslint
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Aug 28, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    57eedfd View commit details
  2. Merge pull request #713 from prettier/dependabot/npm_and_yarn/eslint-…

    …8.48.0
    
    chore(deps-dev): bump eslint from 8.47.0 to 8.48.0
    github-actions[bot] authored Aug 28, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    969c888 View commit details

Commits on Aug 30, 2023

  1. chore(deps-dev): bump prettier from 3.0.2 to 3.0.3

    Bumps [prettier](https://github.com/prettier/prettier) from 3.0.2 to 3.0.3.
    - [Release notes](https://github.com/prettier/prettier/releases)
    - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
    - [Commits](prettier/prettier@3.0.2...3.0.3)
    
    ---
    updated-dependencies:
    - dependency-name: prettier
      dependency-type: direct:development
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Aug 30, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d90981a View commit details
  2. Merge pull request #715 from prettier/dependabot/npm_and_yarn/prettie…

    …r-3.0.3
    
    chore(deps-dev): bump prettier from 3.0.2 to 3.0.3
    github-actions[bot] authored Aug 30, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1295d9c View commit details

Commits on Sep 8, 2023

  1. Copy the full SHA
    e2d7eb1 View commit details

Commits on Sep 11, 2023

  1. chore(deps-dev): bump eslint from 8.48.0 to 8.49.0

    Bumps [eslint](https://github.com/eslint/eslint) from 8.48.0 to 8.49.0.
    - [Release notes](https://github.com/eslint/eslint/releases)
    - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
    - [Commits](eslint/eslint@v8.48.0...v8.49.0)
    
    ---
    updated-dependencies:
    - dependency-name: eslint
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Sep 11, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1613cb7 View commit details
  2. Merge pull request #718 from prettier/dependabot/npm_and_yarn/eslint-…

    …8.49.0
    
    chore(deps-dev): bump eslint from 8.48.0 to 8.49.0
    github-actions[bot] authored Sep 11, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e5497b1 View commit details
  3. Merge pull request #717 from regseb/error

    feat: error similar to the ones thrown by Prettier
    kddnewton authored Sep 11, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    792e3d0 View commit details
  4. Fix self-closing embed

    kddnewton committed Sep 11, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    kddnewton Kevin Newton
    Copy the full SHA
    513f514 View commit details
  5. Merge pull request #719 from prettier/fix-self-closing

    Fix self-closing embed
    kddnewton authored Sep 11, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    eefd999 View commit details
  6. Verified

    This commit was signed with the committer’s verified signature.
    kddnewton Kevin Newton
    Copy the full SHA
    409ff99 View commit details
  7. Bump to version v3.2.1

    kddnewton committed Sep 11, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    kddnewton Kevin Newton
    Copy the full SHA
    69760ec View commit details
Showing with 573 additions and 571 deletions.
  1. +13 −1 CHANGELOG.md
  2. +2 −2 README.md
  3. +2 −2 package.json
  4. +5 −0 src/embed.js
  5. +37 −17 src/parser.js
  6. +7 −0 test/embed.test.js
  7. +12 −0 test/parser.test.js
  8. +495 −549 yarn.lock
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]

## [3.2.1] - 2023-09-11

### Added

- Updated the documentation to reflect that you need to pass the plugin path now.

### Changed

- Error messages thrown by the plugin are now much closer to the error messages thrown by prettier.
- Fixed a bug where self-closing tags that looked like embeds would throw an error.

## [3.2.0] - 2023-08-08

### Added
@@ -228,7 +239,8 @@ and it will maintain your formatting.

- Initial release 🎉

[unreleased]: https://github.com/prettier/plugin-xml/compare/v3.2.0...HEAD
[unreleased]: https://github.com/prettier/plugin-xml/compare/v3.2.1...HEAD
[3.2.1]: https://github.com/prettier/plugin-xml/compare/v3.2.0...v3.2.1
[3.2.0]: https://github.com/prettier/plugin-xml/compare/v3.1.1...v3.2.0
[3.1.1]: https://github.com/prettier/plugin-xml/compare/v3.1.0...v3.1.1
[3.1.0]: https://github.com/prettier/plugin-xml/compare/v3.0.0...v3.1.0
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ yarn add --dev prettier @prettier/plugin-xml
The `prettier` executable is now installed and ready for use:

```bash
./node_modules/.bin/prettier --write '**/*.xml'
./node_modules/.bin/prettier --plugin=@prettier/plugin-xml --write '**/*.xml'
```

## Configuration
@@ -69,7 +69,7 @@ file](https://prettier.io/docs/en/configuration.html). For example:
Or, they can be passed to `prettier` as arguments:

```bash
prettier --tab-width 4 --write '**/*.xml'
prettier --plugin=@prettier/plugin-xml --tab-width 4 --write '**/*.xml'
```

### Whitespace
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prettier/plugin-xml",
"version": "3.2.0",
"version": "3.2.1",
"description": "prettier plugin for XML",
"type": "module",
"main": "src/plugin.js",
@@ -32,7 +32,7 @@
"husky": "^8.0.0",
"jest": "^29.2.1",
"linguist-languages": "^7.21.0",
"lint-staged": "^13.2.3",
"lint-staged": "^14.0.0",
"prettier": "^3.0.0"
},
"eslintConfig": {
5 changes: 5 additions & 0 deletions src/embed.js
Original file line number Diff line number Diff line change
@@ -124,6 +124,11 @@ function embed(path, opts) {
return;
}

// If the node is self-closing, then skip
if (!node.children.content) {
return;
}

// If the node does not actually contain content, or it contains any content
// that is not just plain text, then skip
const content = node.children.content[0].children;
54 changes: 37 additions & 17 deletions src/parser.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,54 @@
import { parse as xmlToolsParse } from "@xml-tools/parser";

function createError(message, options) {
// TODO: Use `Error.prototype.cause` when we drop support for Node.js<18.7.0

// Construct an error similar to the ones thrown by Prettier.
const error = new SyntaxError(
message +
" (" +
options.loc.start.line +
":" +
options.loc.start.column +
")"
);

return Object.assign(error, options);
}

const parser = {
parse(text) {
const { lexErrors, parseErrors, cst } = xmlToolsParse(text);

// If there are any lexical errors, throw the first of them as an error.
if (lexErrors.length > 0) {
const lexError = lexErrors[0];
const error = new Error(lexError.message);

error.loc = {
start: { line: lexError.line, column: lexError.column },
end: { line: lexError.line, column: lexError.column + lexError.length }
};

throw error;
throw createError(lexError.message, {
loc: {
start: { line: lexError.line, column: lexError.column },
end: {
line: lexError.line,
column: lexError.column + lexError.length
}
}
});
}

// If there are any parse errors, throw the first of them as an error.
if (parseErrors.length > 0) {
const parseError = parseErrors[0];
const error = new Error(parseError.message);

const { token } = parseError;
error.loc = {
start: { line: token.startLine, column: token.startColumn },
end: { line: token.endLine, column: token.endColumn }
};

throw error;
throw createError(parseError.message, {
loc: {
start: {
line: parseError.token.startLine,
column: parseError.token.startColumn
},
end: {
line: parseError.token.endLine,
column: parseError.token.endColumn
}
}
});
}

// Otherwise return the CST.
7 changes: 7 additions & 0 deletions test/embed.test.js
Original file line number Diff line number Diff line change
@@ -89,3 +89,10 @@ customScript!!!

expect(formatted).toEqual(expected);
});

test("does not embed when self-closing", async () => {
const expected = `<script type="text/javascript" />\n`;
const formatted = await format(expected);

expect(formatted).toEqual(expected);
});
12 changes: 12 additions & 0 deletions test/parser.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import parser from "../src/parser.js";

test("parseError", () => {
const expected = new SyntaxError(
"Expecting: one of these possible Token sequences:\n" +
" 1. [CLOSE]\n" +
" 2. [SLASH_CLOSE]\n" +
"but found: '/' (1:6)"
);

expect(() => parser.parse("<foo /")).toThrow(expected);
});
1,044 changes: 495 additions & 549 deletions yarn.lock

Large diffs are not rendered by default.