Skip to content

Commit

Permalink
style: migrate to eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
no23reason committed Feb 25, 2020
1 parent 9719b4c commit 880cd1f
Show file tree
Hide file tree
Showing 8 changed files with 519 additions and 94 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__tests__
158 changes: 158 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
module.exports = {
"env": {},
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/array-type": "error",
"@typescript-eslint/consistent-type-definitions": "error",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
"accessibility": "explicit"
}
],
"@typescript-eslint/indent": [
"error",
2,
{
"FunctionDeclaration": {
"parameters": "first"
},
"FunctionExpression": {
"parameters": "first"
}
}
],
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/member-delimiter-style": [
"error",
{
"multiline": {
"delimiter": "semi",
"requireLast": true
},
"singleline": {
"delimiter": "semi",
"requireLast": false
}
}
],
"@typescript-eslint/member-ordering": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/quotes": [
"error",
"double",
{
"avoidEscape": true
}
],
"@typescript-eslint/semi": [
"error",
"always"
],
"@typescript-eslint/unified-signatures": "error",
"arrow-body-style": "error",
"arrow-parens": [
"off",
"as-needed"
],
"camelcase": "error",
"comma-dangle": [
"error",
"always-multiline"
],
"complexity": "off",
"constructor-super": "error",
"curly": "error",
"dot-notation": "error",
"eol-last": "error",
"eqeqeq": [
"error",
"smart"
],
"guard-for-in": "error",
"id-blacklist": [
"error",
"any",
"Number",
"number",
"String",
"string",
"Boolean",
"boolean",
"Undefined",
"undefined"
],
"id-match": "error",
"max-classes-per-file": [
"error",
1
],
"max-len": [
"error",
{
"code": 120
}
],
"new-parens": "error",
"no-bitwise": "error",
"no-caller": "error",
"no-cond-assign": "error",
"no-console": "error",
"no-debugger": "error",
"no-empty": "error",
"no-eval": "error",
"no-fallthrough": "off",
"no-invalid-this": "off",
"no-multiple-empty-lines": "error",
"no-new-wrappers": "error",
"no-shadow": [
"error",
{
"hoist": "all"
}
],
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef-init": "error",
"no-underscore-dangle": "error",
"no-unsafe-finally": "error",
"no-unused-expressions": "error",
"no-unused-labels": "error",
"object-shorthand": "error",
"one-var": [
"error",
"never"
],
"quote-props": [
"error",
"consistent-as-needed"
],
"radix": "error",
"space-before-function-paren": [
"error",
{
"anonymous": "never",
"asyncArrow": "always",
"named": "never"
}
],
"spaced-comment": "error",
"use-isnan": "error",
"valid-typeof": "off"
}
};
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"prepublishOnly": "npm run build",
"build": "tsc",
"test": "jest --coverage",
"test:ci": "npm run test:tslint && npm test",
"test:ci": "npm run test:eslint && npm test",
"test:tdd": "jest --watch",
"test:tslint": "tslint --project .",
"test:eslint": "eslint -c .eslintrc.js --ext .ts ./src",
"semantic-release": "semantic-release"
},
"dependencies": {
Expand All @@ -38,13 +38,15 @@
"@types/mkdirp": "^1.0.0",
"@types/uuid": "^3.4.3",
"@types/xml2js": "^0.4.2",
"@typescript-eslint/eslint-plugin": "^2.21.0",
"@typescript-eslint/parser": "^2.21.0",
"commitizen": "^4.0.3",
"cz-conventional-changelog": "^3.1.0",
"eslint": "^6.8.0",
"jest": "^25.1.0",
"mkdirp": "^1.0.3",
"semantic-release": "^17.0.4",
"ts-jest": "^25.2.1",
"tslint": "^5.9.1",
"typescript": "^3.7.2",
"xml2js": "^0.4.19"
},
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { generateTrx, IOptions } from "./trx-generator";
class TrxReporter {
private options: IOptions;

constructor(_: Config.GlobalConfig, options: IOptions) {
public constructor(_: Config.GlobalConfig, options: IOptions) {
this.options = {
...options,
defaultUserName: options?.defaultUserName ?? defaultUserName,
Expand All @@ -30,7 +30,7 @@ class TrxReporter {
writeFileSync(this.options.outputFile, trx, { encoding: "utf8" });
process.stdout.write("DONE\n");
process.stdout.write(`TRX file output to '${this.options.outputFile}'\n`);
}
};
}

module.exports = TrxReporter;
14 changes: 8 additions & 6 deletions src/trx-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const renderTestRun = (
testRunResult: AggregatedResult,
computerName: string,
userName?: string,
) =>
): void => {
builder
.att("id", uuid.v4())
.att(
Expand All @@ -67,17 +67,19 @@ const renderTestRun = (
)
.att("runUser", userName)
.att("xmlns", "http://microsoft.com/schemas/VisualStudio/TeamTest/2010");
};

const renderTestSettings = (parentNode: XMLElement) =>
const renderTestSettings = (parentNode: XMLElement): void => {
parentNode
.ele("TestSettings")
.att("name", "Jest test run")
.att("id", uuid.v4());
};

const renderTimes = (
parentNode: XMLElement,
testRunResult: AggregatedResult,
) => {
): void => {
const startTime = new Date(testRunResult.startTime).toISOString();
parentNode
.ele("Times")
Expand All @@ -90,7 +92,7 @@ const renderTimes = (
const renderResultSummary = (
parentNode: XMLElement,
testRunResult: AggregatedResult,
) => {
): void => {
// workaround for https://github.com/facebook/jest/issues/6924
const anyTestFailures = !(
testRunResult.numFailedTests === 0 &&
Expand Down Expand Up @@ -118,7 +120,7 @@ const renderResultSummary = (
.att("error", testRunResult.numRuntimeErrorTestSuites);
};

const renderTestLists = (parentNode: XMLElement) => {
const renderTestLists = (parentNode: XMLElement): void => {
const testLists = parentNode.ele("TestLists");

testLists
Expand All @@ -145,7 +147,7 @@ const renderTestSuiteResult = (
testResultNode: XMLElement,
) => void,
],
) => {
): void => {
const perTestDuration = getSuitePerTestDuration(testSuiteResult);
const perTestDurationFormatted = formatDuration(perTestDuration);

Expand Down
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export const getSuitePerTestDuration = (testSuiteResult: TestResult): number =>
testSuiteResult.numPendingTests),
);

export const getEnvInfo = (defaultUserName = "anonymous") => ({
export const getEnvInfo = (
defaultUserName = "anonymous",
): { computerName: string; userName: string } => ({
computerName: os.hostname(),
userName:
process.env.SUDO_USER ||
Expand Down
8 changes: 0 additions & 8 deletions tslint.json

This file was deleted.

Loading

0 comments on commit 880cd1f

Please sign in to comment.