Skip to content

Commit

Permalink
Set up eslint, tslint, and prettier (alangpierce#2)
Browse files Browse the repository at this point in the history
Fow now it only runs on the main typescript code, but I'll enable it on the
parser later.
  • Loading branch information
alangpierce authored Dec 22, 2017
1 parent 45ad769 commit 76b67ad
Show file tree
Hide file tree
Showing 21 changed files with 1,830 additions and 792 deletions.
35 changes: 35 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const tslintRules = require('./tslint.json');

module.exports = {
"extends": ["airbnb-base", "prettier"],
parser: 'typescript-eslint-parser',
// Add typescript plugin but don't use it, since that tells WebStorm to run
// ESLint for .ts files.
plugins: ['prettier', 'tslint', 'typescript'],
rules: {
"class-methods-use-this": "off",
"import/extensions": "off",
"no-constant-condition": ["error", {"checkLoops": false}],
"no-continue": "off",
"no-empty-function": "off",
"no-param-reassign": "off",
"no-plusplus": "off",
"no-restricted-syntax": "off",
"no-undef": "off",
"no-unused-vars": "off",
"no-use-before-define": "off",
// False positive on TS constructors with initializers.
"no-useless-constructor": "off",
"prefer-destructuring": "off",
"prettier/prettier": "error",
"tslint/config": ["error", tslintRules],
},
settings: {
"import/extensions": ['.js', '.ts'],
"import/resolver": {
node: {
extensions: ['.js', '.ts'],
},
},
},
};
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"arrowParens": "always",
"bracketSpacing": false,
"parser": "typescript",
"printWidth": 100,
"trailingComma": "all",
}
50 changes: 26 additions & 24 deletions benchmark/benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
#!/usr/bin/env node
import * as fs from 'fs';

/* eslint-disable import/no-extraneous-dependencies */
// @ts-ignore: buble missing types
import * as babel from "@babel/core";
// @ts-ignore: new babel-core package missing types.
import * as babel from '@babel/core';
// Use require rather than import to hack around missing type info.
const buble = require('buble');
import * as sucrase from '../src/index';
import * as TypeScript from 'typescript';
import * as buble from "buble";
import * as fs from "fs";
import * as TypeScript from "typescript";

import * as sucrase from "../src/index";

function main(): void {
console.log('Simulating transpilation of 100,000 lines of code:');
const code = fs.readFileSync('./benchmark/sample.js').toString();
runBenchmark('Sucrase', () => sucrase.transform(
code,
{transforms: ['jsx', 'imports', 'add-module-exports', 'react-display-name']})
console.log("Simulating transpilation of 100,000 lines of code:");
const code = fs.readFileSync("./benchmark/sample.js").toString();
runBenchmark("Sucrase", () =>
sucrase.transform(code, {
transforms: ["jsx", "imports", "add-module-exports", "react-display-name"],
}),
);
runBenchmark('Buble (JSX, no import transform)', () =>
buble.transform(code, {transforms: {modules: false}})
runBenchmark("Buble (JSX, no import transform)", () =>
buble.transform(code, {transforms: {modules: false}}),
);
runBenchmark('TypeScript', () =>
runBenchmark("TypeScript", () =>
TypeScript.transpileModule(code, {
compilerOptions: {
module: TypeScript.ModuleKind.CommonJS,
jsx: TypeScript.JsxEmit.React,
target: TypeScript.ScriptTarget.ESNext
}
})
target: TypeScript.ScriptTarget.ESNext,
},
}),
);
runBenchmark("Babel", () =>
babel.transform(code, {
presets: ["@babel/preset-react"],
plugins: ["@babel/plugin-transform-modules-commonjs"],
}),
);
runBenchmark('Babel', () => babel.transform(
code,
{
presets: ['@babel/preset-react'],
plugins: ['@babel/plugin-transform-modules-commonjs']
}));
}

function runBenchmark(name: string, runTrial: () => void): void {
Expand Down
2 changes: 2 additions & 0 deletions benchmark/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import * as sucrase from '../src/index';
function main(): void {
console.log('Profiling Sucrase on about 100,000 LOC. Make sure you have Chrome DevTools for Node open.');
const code = fs.readFileSync('./benchmark/sample.js').toString();
// tslint:disable-next-line no-any
(console as any).profile('Sucrase');
for (let i = 0; i < 1000; i++) {
sucrase.transform(
code,
{transforms: ['jsx', 'imports', 'add-module-exports', 'react-display-name']}
);
}
// tslint:disable-next-line no-any
(console as any).profileEnd('Sucrase');
}

Expand Down
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"scripts": {
"build": "script/build",
"benchmark": "node ./build/benchmark/benchmark.js",
"lint": "eslint './src/**/*.ts' && tslint -p .",
"profile": "node --inspect-brk ./build/benchmark/profile.js",
"prepublish": "yarn run build",
"test": "mocha test"
"test": "yarn lint && mocha test"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -43,9 +44,19 @@
"@types/node": "^8.0.31",
"babel-plugin-transform-charcodes": "0.0.10",
"buble": "^0.16.0",
"eslint": "^4.13.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-prettier": "^2.4.0",
"eslint-plugin-tslint": "^2.1.0",
"eslint-plugin-typescript": "^0.8.1",
"mocha": "^3.5.3",
"prettier": "^1.9.2",
"ts-node": "^4.0.2",
"typescript": "^2.6.2"
"tslint": "^5.8.0",
"typescript": "^2.6.2",
"typescript-eslint-parser": "^11.0.0"
},
"dependencies": {
"charcodes": "0.0.10",
Expand Down
Loading

0 comments on commit 76b67ad

Please sign in to comment.