Skip to content

Commit

Permalink
chore: update infra (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang authored Sep 16, 2018
1 parent 38538d2 commit 9349dd6
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ before_install:
script:
- yarn run lint
- yarn run build
- yarn run test-coverage
- yarn run test

after_script:
- codecov
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
},
"license": "MIT",
"scripts": {
"prepublish": "yarn run build -- --inlineSourceMap false",
"lint": "tslint -p ./tsconfig.json --type-check",
"test": "tslint --test ./tests/*/*",
"test-coverage": "nyc yarn run test",
"build": "rm -rf ./rules && tsc -p tsconfig.build.json",
"prepublish": "yarn run build --inlineSourceMap false",
"lint": "tslint -p .",
"test": "nyc tslint --test ./tests/*/*",
"prebuild": "rm -rf ./rules",
"build": "tsc -p ./tsconfig.build.json",
"release": "standard-version"
},
"dependencies": {
Expand All @@ -32,16 +32,16 @@
},
"devDependencies": {
"@types/eslint-plugin-prettier": "2.2.0",
"@types/node": "8.10.29",
"@types/node": "4.2.23",
"@types/prettier": "1.13.2",
"nyc": "11.9.0",
"prettier": "1.14.2",
"prettier-config-ikatyang": "1.1.1",
"standard-version": "4.4.0",
"tslint": "5.11.0",
"tslint-config-ikatyang": "2.5.1",
"tslint-config-prettier": "1.15.0",
"typescript": "2.9.2"
"tslint-plugin-prettier": "1.3.0",
"typescript": "3.0.3"
},
"peerDependencies": {
"prettier": "^1.4.0",
Expand Down
58 changes: 25 additions & 33 deletions src/prettierRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@ import * as prettier from 'prettier';
import * as tslint from 'tslint';
import * as ts from 'typescript';

// tslint:disable:max-classes-per-file no-use-before-declare

export class Rule extends tslint.Rules.AbstractRule {
public apply(source_file: ts.SourceFile): tslint.RuleFailure[] {
public apply(sourceFile: ts.SourceFile): tslint.RuleFailure[] {
return this.applyWithWalker(
new Walker(source_file, this.ruleName, this.ruleArguments),
new Walker(sourceFile, this.ruleName, this.ruleArguments),
);
}
}

class Walker extends tslint.AbstractWalker<any[]> {
public walk(source_file: ts.SourceFile) {
const [rule_argument_1] = this.options;
public walk(sourceFile: ts.SourceFile) {
const [ruleArgument1] = this.options;

let options: prettier.Options = {};

switch (typeof rule_argument_1) {
switch (typeof ruleArgument1) {
case 'object':
options = rule_argument_1 as prettier.Options;
options = ruleArgument1 as prettier.Options;
break;
case 'string': {
try {
Expand All @@ -37,18 +35,15 @@ class Walker extends tslint.AbstractWalker<any[]> {
);
}

const file_path = path.resolve(
process.cwd(),
rule_argument_1 as string,
);
const resolved_config = prettier.resolveConfig.sync(file_path);
const filePath = path.resolve(process.cwd(), ruleArgument1 as string);
const resolvedConfig = prettier.resolveConfig.sync(filePath);

// istanbul ignore next
if (resolved_config === null) {
throw new Error(`Config file not found: ${file_path}`);
if (resolvedConfig === null) {
throw new Error(`Config file not found: ${filePath}`);
}

options = resolved_config;
options = resolvedConfig;
break;
}
default: {
Expand All @@ -60,19 +55,17 @@ class Walker extends tslint.AbstractWalker<any[]> {
break;
}

const resolved_config = prettier.resolveConfig.sync(
source_file.fileName,
);
const resolvedConfig = prettier.resolveConfig.sync(sourceFile.fileName);

if (resolved_config !== null) {
options = resolved_config;
if (resolvedConfig !== null) {
options = resolvedConfig;
}

break;
}
}

const source = source_file.getFullText();
const source = sourceFile.getFullText();
const formatted = prettier.format(source, {
parser: 'typescript',
...options,
Expand All @@ -86,37 +79,37 @@ class Walker extends tslint.AbstractWalker<any[]> {
const {
operation,
offset: start,
deleteText: delete_text = '',
insertText: insert_text = '',
deleteText = '',
insertText = '',
} = difference;

const end = start + delete_text.length;
const delete_code = utils.showInvisibles(delete_text);
const insert_code = utils.showInvisibles(insert_text);
const end = start + deleteText.length;
const deleteCode = utils.showInvisibles(deleteText);
const insertCode = utils.showInvisibles(insertText);

switch (operation) {
case 'insert':
this.addFailureAt(
start,
1,
`Insert \`${insert_code}\``,
tslint.Replacement.appendText(start, insert_text),
`Insert \`${insertCode}\``,
tslint.Replacement.appendText(start, insertText),
);
break;
case 'delete':
this.addFailure(
start,
end,
`Delete \`${delete_code}\``,
`Delete \`${deleteCode}\``,
tslint.Replacement.deleteFromTo(start, end),
);
break;
case 'replace':
this.addFailure(
start,
end,
`Replace \`${delete_code}\` with \`${insert_code}\``,
tslint.Replacement.replaceFromTo(start, end, insert_text),
`Replace \`${deleteCode}\` with \`${insertCode}\``,
tslint.Replacement.replaceFromTo(start, end, insertText),
);
break;
// istanbul ignore next
Expand All @@ -128,6 +121,5 @@ class Walker extends tslint.AbstractWalker<any[]> {
}

function assert_existence_of_resolve_config_sync() {
// tslint:disable-next-line:strict-type-predicates
assert(typeof prettier.resolveConfig.sync === 'function');
}
8 changes: 3 additions & 5 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"rulesDirectory": [
"./rules"
],
"rulesDirectory": ["tslint-plugin-prettier"],
"extends": [
"tslint-config-ikatyang",
"tslint:recommended",
"tslint-config-prettier",
"prettier-config-ikatyang/tslint"
],
"rules": {
"filename-convention": [true, { "allowPatterns": ["Rule$"] }]
"max-classes-per-file": false
}
}
86 changes: 12 additions & 74 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
version "2.2.0"
resolved "https://registry.yarnpkg.com/@types/eslint-plugin-prettier/-/eslint-plugin-prettier-2.2.0.tgz#26170ee65ce05d811f3ef6fc2987acd525066c7f"

"@types/node@8.10.29":
version "8.10.29"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.29.tgz#b3a13b58dd7b0682bf1b42022bef4a5a9718f687"
"@types/node@4.2.23":
version "4.2.23"
resolved "https://registry.yarnpkg.com/@types/node/-/node-4.2.23.tgz#9241f00d64eb91084f68367746ef10d5fb2f2fc4"

"@types/prettier@1.13.2":
version "1.13.2"
Expand Down Expand Up @@ -637,13 +637,6 @@ diff@^3.2.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"

doctrine@^0.7.2:
version "0.7.2"
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-0.7.2.tgz#7cb860359ba3be90e040b26b729ce4bfa654c523"
dependencies:
esutils "^1.1.6"
isarray "0.0.1"

dot-prop@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-3.0.0.tgz#1b708af094a49c9a0e7dbcad790aba539dac1177"
Expand Down Expand Up @@ -678,10 +671,6 @@ esprima@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"

esutils@^1.1.6:
version "1.1.6"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-1.1.6.tgz#c01ccaa9ae4b897c6d0c3e210ae52f3c7a844375"

esutils@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"
Expand Down Expand Up @@ -1095,10 +1084,6 @@ is-windows@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d"

isarray@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf"

isarray@1.0.0, isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
Expand Down Expand Up @@ -1268,18 +1253,6 @@ lodash._reinterpolate@~3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"

lodash.camelcase@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"

lodash.kebabcase@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36"

lodash.snakecase@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz#39d714a35357147837aefd64b5dcbb16becd8f8d"

lodash.template@^4.0.2:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.4.0.tgz#e73a0385c8355591746e020b99679c690e68fba0"
Expand All @@ -1293,10 +1266,6 @@ lodash.templatesettings@^4.0.0:
dependencies:
lodash._reinterpolate "~3.0.0"

lodash.upperfirst@^4.3.1:
version "4.3.1"
resolved "https://registry.yarnpkg.com/lodash.upperfirst/-/lodash.upperfirst-4.3.1.tgz#1365edf431480481ef0d1c68957a5ed99d49f7ce"

lodash@^4.17.4, lodash@^4.2.1:
version "4.17.10"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"
Expand Down Expand Up @@ -2175,47 +2144,20 @@ trim-right@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"

tslib@^1.0.0, tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1:
tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"

tslint-config-ikatyang@2.5.1:
version "2.5.1"
resolved "https://registry.yarnpkg.com/tslint-config-ikatyang/-/tslint-config-ikatyang-2.5.1.tgz#d99a5479e5386f639b9a07e50a33588bc5c64070"
dependencies:
tslint-consistent-codestyle "~1.8.0"
tslint-eslint-rules "~4.1.0"
tslint-plugin-ikatyang "~1.1.1"

tslint-config-prettier@1.15.0:
version "1.15.0"
resolved "https://registry.yarnpkg.com/tslint-config-prettier/-/tslint-config-prettier-1.15.0.tgz#76b9714399004ab6831fdcf76d89b73691c812cf"

tslint-consistent-codestyle@~1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/tslint-consistent-codestyle/-/tslint-consistent-codestyle-1.8.0.tgz#ede0b5ec6777f8ff4426d9838bc9bf18e8174480"
dependencies:
tslib "^1.7.1"
tsutils "^2.12.0"

tslint-eslint-rules@~4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/tslint-eslint-rules/-/tslint-eslint-rules-4.1.1.tgz#7c30e7882f26bc276bff91d2384975c69daf88ba"
dependencies:
doctrine "^0.7.2"
tslib "^1.0.0"
tsutils "^1.4.0"

tslint-plugin-ikatyang@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/tslint-plugin-ikatyang/-/tslint-plugin-ikatyang-1.1.1.tgz#a7815bba6267b7f820fd52aa6baec5041ac721f5"
tslint-plugin-prettier@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/tslint-plugin-prettier/-/tslint-plugin-prettier-1.3.0.tgz#7eb65d19ea786a859501a42491b78c5de2031a3f"
dependencies:
lodash.camelcase "^4.3.0"
lodash.kebabcase "^4.1.1"
lodash.snakecase "^4.1.1"
lodash.upperfirst "^4.3.1"
eslint-plugin-prettier "^2.2.0"
tslib "^1.7.1"
tsutils "^2.8.0"

tslint@5.11.0:
version "5.11.0"
Expand All @@ -2234,11 +2176,7 @@ tslint@5.11.0:
tslib "^1.8.0"
tsutils "^2.27.2"

tsutils@^1.4.0:
version "1.9.1"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-1.9.1.tgz#b9f9ab44e55af9681831d5f28d0aeeaf5c750cb0"

tsutils@^2.12.0, tsutils@^2.27.2, tsutils@^2.8.0:
tsutils@^2.27.2:
version "2.29.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.29.0.tgz#32b488501467acbedd4b85498673a0812aca0b99"
dependencies:
Expand All @@ -2248,9 +2186,9 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript@2.9.2:
version "2.9.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c"
typescript@3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.3.tgz#4853b3e275ecdaa27f78fda46dc273a7eb7fc1c8"

uglify-js@^2.6:
version "2.8.29"
Expand Down

0 comments on commit 9349dd6

Please sign in to comment.