Skip to content

Commit

Permalink
Switch to TypeScript (#8)
Browse files Browse the repository at this point in the history
* Remove ESlint
* Move scripts to the top of package.json to make them quicker to scan through
* Move test files into src and fixtures to root folder
* Use import / export instead of require / module.exports
* Add typescript modules and configs
* Re-configure Prettier
  • Loading branch information
kachkaev committed Dec 22, 2018
1 parent 0aea2ea commit bbf66dc
Show file tree
Hide file tree
Showing 50 changed files with 1,063 additions and 901 deletions.
40 changes: 0 additions & 40 deletions .eslintrc.yml

This file was deleted.

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
node_modules
*.log
/.vscode
.DS_Store
cache
coverage
.idea
dist
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!dist/**/*
dist/**/*.test.*
!package.json
!README.md
!LICENSE
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ before_script:
- ./cc-test-reporter before-build
script:
- yarn lint
- yarn test:coverage
- yarn test --coverage
after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
notifications:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
collectCoverageFrom: ["dist/**/*.js", "!dist/**/*.test.js"],
};
8 changes: 0 additions & 8 deletions jest.eslint.config.js

This file was deleted.

8 changes: 0 additions & 8 deletions jest.test.config.js

This file was deleted.

64 changes: 30 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
{
"name": "prettier-plugin-elm",
"version": "0.4.1",
"main": "src",
"license": "BSD-3-Clause",
"repository": "https://github.com/gicentre/prettier-plugin-elm",
"description": "Adds Elm language support to Prettier via elm-format",
"license": "BSD-3-Clause",
"files": [
"src"
],
"scripts": {
"build": "tsc --project .",
"clean": "rimraf cache coverage dist",
"format": "prettier --write {*,src/**/*}.{md,js,json,ts}",
"lint": "tsc --project . --noEmit && tslint --project . && prettier --check {*,src/**/*}.{md,js,json,ts}",
"test": "yarn clean && yarn build && jest",
"prepublishOnly": "yarn lint && yarn test"
},
"main": "dist",
"keywords": [
"elm",
"elm-format",
"gicentre",
"prettier",
"prettier-plugin"
],
"scripts": {
"clean:coverage": "rimraf coverage",
"clean:test": "rimraf cache",
"lint": "jest -c jest.eslint.config.js && prettier-check {*,src/**/*,test/*}.{md,js}",
"test": "jest -c jest.test.config.js --no-coverage",
"test:coverage": "jest -c jest.test.config.js",
"format": "prettier --write --plugin=. {*,src/**,test/**}.{md,js}",
"prepublishOnly": "yarn lint && yarn test"
},
"devDependencies": {
"eslint": "^5.7.0",
"eslint-config-prettier": "^3.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^21.24.1",
"eslint-plugin-prettier": "^3.0.0",
"jest": "^23.6.0",
"jest-runner-eslint": "^0.6.0",
"prettier": "^1.14.3",
"prettier-check": "^2.0.0",
"rimraf": "^2.6.2",
"sleep-promise": "^8.0.1"
"husky": {
"hooks": {
"pre-push": "yarn lint"
}
},
"dependencies": {
"elm-format": "^0.8.1",
Expand All @@ -45,13 +33,21 @@
"serialize-error": "^3.0.0",
"temp-dir": "^1.0.0"
},
"prettier": {},
"eslintIgnore": [
"coverage"
],
"husky": {
"hooks": {
"pre-push": "yarn lint"
}
"devDependencies": {
"@types/execa": "^0.9.0",
"@types/jest": "^23.3.10",
"@types/make-dir": "^1.0.3",
"@types/object-hash": "^1.2.0",
"@types/prettier": "^1.15.2",
"@types/rimraf": "^2.0.2",
"@types/serialize-error": "^2.1.0",
"@types/temp-dir": "^1.0.0",
"jest": "^23.6.0",
"prettier": "prettier/prettier#439b1649ff9298b56b4f5e68214de6c2b29c6f26",
"rimraf": "^2.6.2",
"sleep-promise": "^8.0.1",
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.17.0",
"typescript": "^3.2.2"
}
}
5 changes: 5 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
arrowParens: "always",
endOfLine: "lf",
trailingComma: "all",
};
49 changes: 23 additions & 26 deletions test/caching.test.js → src/cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
"use strict";
import * as fs from "fs";
import { resolve } from "path";
import * as prettier from "prettier";
import * as rimraf from "rimraf";
import * as sleep from "sleep-promise";
import * as util from "./util";

const fs = require("fs");
const path = require("path");
const prettier = require("prettier");
const rimraf = require("rimraf");
const sleep = require("sleep-promise");

const util = require("../src/util");

const fixturesDirName = path.resolve(__dirname, "fixtures");
const cacheDir = path.resolve(__dirname, "../cache");
const fixturesDir = resolve(__dirname, "../fixtures");
const cacheDir = resolve(__dirname, "../cache");
const cacheMax = 21; // number of blocks in multiple-blocks.md fixture
const cacheGCInterval = 1000;

Expand All @@ -21,24 +18,24 @@ test(`correctly deals with cache`, () => {

const spyForFormatTextWithElmFormat = jest.spyOn(
util,
"formatTextWithElmFormat"
"formatTextWithElmFormat",
);

const sourceText = fs.readFileSync(
path.resolve(fixturesDirName, "multiple-blocks.md"),
"utf8"
resolve(fixturesDir, "multiple-blocks.md"),
"utf8",
);
const expectedFormattedText = fs.readFileSync(
path.resolve(fixturesDirName, "multiple-blocks.prettified.md"),
"utf8"
resolve(fixturesDir, "multiple-blocks.prettified.md"),
"utf8",
);

// multiple-blocks.md, first run – no cache
expect(
prettier.format(sourceText, {
parser: "markdown",
plugins: [path.resolve(__dirname, "..")]
})
plugins: [resolve(__dirname, "..")],
}),
).toEqual(expectedFormattedText);
const numberOfFormatCallsInFirstRun =
spyForFormatTextWithElmFormat.mock.calls.length;
Expand All @@ -48,29 +45,29 @@ test(`correctly deals with cache`, () => {
expect(
prettier.format(sourceText, {
parser: "markdown",
plugins: [path.resolve(__dirname, "..")]
})
plugins: [resolve(__dirname, "..")],
}),
).toEqual(expectedFormattedText);
expect(spyForFormatTextWithElmFormat.mock.calls.length).toBe(
numberOfFormatCallsInFirstRun
numberOfFormatCallsInFirstRun,
);

return sleep(cacheGCInterval * 2).then(() => {
// a call to formatTextWithElmFormat() that triggers garbage collection
prettier.format("{- -}", {
parser: "elm",
plugins: [path.resolve(__dirname, "..")]
parser: "elm" as any,
plugins: [resolve(__dirname, "..")],
});

// multiple-blocks.md, third run – with cache except for one block that was previously garbage collected
expect(
prettier.format(sourceText, {
parser: "markdown",
plugins: [path.resolve(__dirname, "..")]
})
plugins: [resolve(__dirname, "..")],
}),
).toEqual(expectedFormattedText);
expect(spyForFormatTextWithElmFormat.mock.calls.length).toBe(
numberOfFormatCallsInFirstRun + 1 /* for "" */ + 1 /* for GC-d block */
numberOfFormatCallsInFirstRun + 1 /* for "" */ + 1 /* for GC-d block */,
);
});
});
Loading

0 comments on commit bbf66dc

Please sign in to comment.