Skip to content

Commit

Permalink
Merge pull request #191 from ember-template-lint/esm-v4
Browse files Browse the repository at this point in the history
Convert to ESM for ember-template-lint v4
  • Loading branch information
dcyriller authored Jan 3, 2022
2 parents 9d40641 + 53710e7 commit 702dd43
Show file tree
Hide file tree
Showing 9 changed files with 511 additions and 459 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ module.exports = {
"plugin:node/recommended",
"plugin:prettier/recommended",
],
parserOptions: {
ecmaVersion: 2021,
sourceType: "module",
},
plugins: ["prettier"],
env: {
node: true,
Expand Down
7 changes: 4 additions & 3 deletions ember-template-lint-plugin-prettier.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const PrettierRule = require("./lib/rules/prettier");
import PrettierRule from "./lib/rules/prettier.js";
import recommended from "./lib/config/recommended.js";

module.exports = {
export default {
name: "ember-template-lint-plugin-prettier",

configurations: {
recommended: {
rules: require("./lib/config/recommended"),
rules: recommended,
},
},

Expand Down
4 changes: 1 addition & 3 deletions lib/config/recommended.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"use strict";

module.exports = {
export default {
prettier: true,
// ember-template-lint stylistic rules
"block-indentation": false,
Expand Down
16 changes: 7 additions & 9 deletions lib/rules/prettier.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
"use strict";
import { showInvisibles, generateDifferences } from "prettier-linter-helpers";

const {
showInvisibles,
generateDifferences,
} = require("prettier-linter-helpers");
import getLocFromIndex from "../utils/get-loc-from-index.js";
import { createRequire } from "node:module";

const getLocFromIndex = require("../utils/get-loc-from-index");
const require = createRequire(import.meta.url);

const { INSERT, DELETE, REPLACE } = generateDifferences;

let prettier;

const { Rule, recast } = require("ember-template-lint");
import { Rule, recast } from "ember-template-lint";

function isFile(loc) {
return loc.start && loc.start.line === 1 && loc.start.column === 0;
}

module.exports = class Prettier extends Rule {
export default class Prettier extends Rule {
constructor(options) {
super(options);
this.filePath = options.filePath;
Expand Down Expand Up @@ -154,4 +152,4 @@ module.exports = class Prettier extends Rule {
},
};
}
};
}
4 changes: 2 additions & 2 deletions lib/utils/get-loc-from-index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function getLocFromIndex(index, lines) {
export default function getLocFromIndex(index, lines) {
// pop potential final newline
// indeed, we won't display a message on this character
// but instead on the previous one
Expand Down Expand Up @@ -38,4 +38,4 @@ module.exports = function getLocFromIndex(index, lines) {
}

return { line, column };
};
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"repository": "git@github.com:ember-template-lint/ember-template-lint-plugin-prettier.git",
"license": "Apache-2.0",
"author": "Cyrille David <'cyrille@qonto.eu'>",
"main": "ember-template-lint-plugin-prettier.js",
"main": "./ember-template-lint-plugin-prettier.js",
"exports": "./ember-template-lint-plugin-prettier.js",
"type": "module",
"files": [
"ember-template-lint-plugin-prettier.js",
"lib",
Expand All @@ -31,7 +33,7 @@
"prettier-linter-helpers": "^1.0.0"
},
"devDependencies": {
"ember-template-lint": "^4.0.0-beta.0",
"ember-template-lint": "^4.0.0-beta.3",
"eslint": "^8.2.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-node": "^11.0.0",
Expand All @@ -49,7 +51,7 @@
"prettier": ">=1.18.1"
},
"engines": {
"node": "12.* || 14.* || >= 16.*"
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
Expand All @@ -70,7 +72,7 @@
}
},
"volta": {
"node": "12.22.7",
"node": "16.13.1",
"yarn": "1.22.17"
}
}
4 changes: 2 additions & 2 deletions test/unit/rules/lint-prettier-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { generateRuleTests } = require("ember-template-lint");
const plugin = require("../../../ember-template-lint-plugin-prettier");
import { generateRuleTests } from "ember-template-lint";
import plugin from "../../../ember-template-lint-plugin-prettier.js";

generateRuleTests({
name: "prettier",
Expand Down
4 changes: 2 additions & 2 deletions test/unit/utils/get-loc-from-index-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint node/no-deprecated-api: 'off' */
const assert = require("assert");
const getLocFromIndex = require("../../../lib/utils/get-loc-from-index");
import assert from "node:assert";
import getLocFromIndex from "../../../lib/utils/get-loc-from-index.js";

describe("getLocFromIndex()", function () {
describe("when end-of-file === newline", function () {
Expand Down
Loading

0 comments on commit 702dd43

Please sign in to comment.