Skip to content

Commit fc20b90

Browse files
committed
fix lint
1 parent 0baf501 commit fc20b90

File tree

10 files changed

+121
-104
lines changed

10 files changed

+121
-104
lines changed

.editorconfig

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[{package.json,.babelrc}]
15+
indent_style = space
16+
indent_size = 2
17+
18+
[*.{js,ts,scss,vue,yml}]
19+
indent_style = space
20+
indent_size = 2
21+
22+
[*.{php,json,conf}]
23+
indent_style = space
24+
indent_size = 4

.npmrc

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
package-lock=false
2+
.travis.yml
3+
tests/*

dist/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { PathLike } from 'fs';
55
import LineByLine = require('n-readlines');
66
export declare class MyLineReader extends LineByLine {
77
val: string;
8-
nextVal: string;
8+
nextValue: string;
99
lineNumber: number;
1010
myFile: string | undefined;
1111
charset: any;

dist/index.js

+9-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/types.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,25 @@
3131
"compare-files"
3232
],
3333
"dependencies": {
34-
"@types/n-readlines": "^1.0.1"
34+
"@types/n-readlines": "^1.0.1",
35+
"n-readlines": "^1.0.1"
3536
},
3637
"devDependencies": {
3738
"@types/node": "^14.14.21",
38-
"ava": "^2.4.0",
39+
"ava": "^3.15.0",
3940
"cross-env": "^7.0.3",
4041
"debug": "^4.3.1",
41-
"n-readlines": "^1.0.1",
42-
"nyc": "^14.1.1",
42+
"nyc": "^15.1.0",
4343
"ts-node": "^9.1.1",
4444
"typescript": "^4.1.3",
45-
"xo": "^0.25.3"
45+
"xo": "^0.37.1"
4646
},
4747
"xo": {
4848
"semicolon": true,
4949
"prefer-const": false,
5050
"space": 2,
5151
"rules": {
52+
"@typescript-eslint/no-inferrable-types": "off",
5253
"object-shorthand": [
5354
0,
5455
"consistent"

src/index.ts

+15-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { EventEmitter } from 'events';
2-
import { TextFileDiffOption } from './types';
3-
import { PathLike } from 'fs';
1+
import {EventEmitter} from 'events';
2+
import {TextFileDiffOption} from './types';
3+
import {PathLike} from 'fs';
44

55
import LineByLine = require('n-readlines');
66
import myDebug = require('debug');
@@ -9,7 +9,7 @@ const debug = myDebug('text-file-diff');
99

1010
export class MyLineReader extends LineByLine {
1111
val: string = '';
12-
nextVal: string = '';
12+
nextValue: string = '';
1313
lineNumber: number = -1;
1414
myFile: string | undefined = undefined;
1515
charset: any = 'utf8';
@@ -20,19 +20,19 @@ export class MyLineReader extends LineByLine {
2020
// move to first line
2121
this.moveNext();
2222
this.moveNext();
23-
return this;
2423
}
24+
2525
moveNext(): string {
26-
this.val = this.nextVal;
26+
this.val = this.nextValue;
2727

28-
let nextVal:any = this.next();
28+
let nextValue: any = this.next();
2929

30-
if (nextVal === false) {
30+
if (nextValue === false) {
3131
this.eof++;
32-
nextVal = '';
32+
nextValue = '';
3333
}
34-
35-
this.nextVal = nextVal.toString(this.charset);
34+
35+
this.nextValue = nextValue.toString(this.charset);
3636
this.lineNumber++;
3737
return this.val;
3838
}
@@ -48,7 +48,6 @@ export default class TextFileDiff extends EventEmitter {
4848
super();
4949
this.options = new TextFileDiffOption();
5050
Object.assign(this.options, options);
51-
return this;
5251
}
5352

5453
/**
@@ -60,10 +59,7 @@ export default class TextFileDiff extends EventEmitter {
6059
diff(file1: string, file2: string) {
6160
const lineReader1 = new MyLineReader(file1);
6261
const lineReader2 = new MyLineReader(file2);
63-
const compareFn = this.options.compareFn;
64-
const charset = this.options.charset;
65-
66-
let stop = false;
62+
const {compareFn, charset} = this.options;
6763

6864
lineReader1.charset = charset;
6965
lineReader2.charset = charset;
@@ -85,10 +81,10 @@ export default class TextFileDiff extends EventEmitter {
8581
// forEach line in File1, compare to line in File2
8682
const line1 = lineReader1.val;
8783
const line2 = lineReader2.val;
88-
const cmp = this.options.compareFn(line1, line2);
89-
// debug(lineReader1.val, lineReader2.val, cmp);
90-
// debug(lineReader1.nextVal, lineReader2.nextVal, 'next', lineReader1.eof, lineReader2.eof);
84+
const cmp = this.options.compareFn(line1, line2);
9185

86+
// debug(lineReader1.val, lineReader2.val, cmp);
87+
// debug(lineReader1.nextValue, lineReader2.nextValue, 'next', lineReader1.eof, lineReader2.eof);
9288
// emit on compared
9389
this.emit('compared', line1, line2, cmp, lineReader1, lineReader2);
9490

@@ -99,7 +95,6 @@ export default class TextFileDiff extends EventEmitter {
9995
} else if (cmp > 0) {
10096
// line1 > line2: new line detected
10197
if (cmp === 1) {
102-
10398
// if file2 ended before file1, then file2 lost line1
10499
// else file2 has new line
105100
if (lineReader2.eof > lineReader1.eof) {
@@ -114,7 +109,6 @@ export default class TextFileDiff extends EventEmitter {
114109
} else if (cmp < 0) {
115110
// line1 < line2: deleted line
116111
if (cmp === -1) {
117-
118112
// if file1 ended before file2, then file2 has new line
119113
// else file1 lost a line
120114
if (lineReader1.eof > lineReader2.eof) {

src/types.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { EventEmitter } from 'events';
1+
import {EventEmitter} from 'events';
22

33
export class TextFileDiffOption {
4-
skipHeader: boolean = false;
5-
charset: any = 'utf8';
6-
compareFn (line1: string, line2: string) {
7-
return line1 > line2 ? 1 : (line1 < line2 ? -1 : 0);
8-
}
4+
skipHeader: boolean = false;
5+
charset: any = 'utf8';
6+
compareFn(line1: string, line2: string) {
7+
return line1 > line2 ? 1 : (line1 < line2 ? -1 : 0);
8+
}
99
}

tests/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import test from 'ava';
2-
import TextFileDiff from '../dist';
1+
const test = require('ava');
2+
const TextFileDiff = require('../dist/index.js').default;
33

44
test('test with header', t => {
55
const m = new TextFileDiff();

tsconfig.json

+55-55
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
{
2-
"compilerOptions": {
3-
/* Basic Options */
4-
"target": "es2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
5-
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
6-
"skipLibCheck": true,
7-
// "lib": [], /* Specify library files to be included in the compilation: */
8-
// "allowJs": true, /* Allow javascript files to be compiled. */
9-
// "checkJs": true, /* Report errors in .js files. */
10-
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
11-
"declaration": true, /* Generates corresponding '.d.ts' file. */
12-
// "sourceMap": true, /* Generates corresponding '.map' file. */
13-
// "outFile": "./", /* Concatenate and emit output to single file. */
14-
"outDir": "./dist", /* Redirect output structure to the directory. */
15-
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
16-
// "removeComments": true, /* Do not emit comments to output. */
17-
// "noEmit": true, /* Do not emit outputs. */
18-
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
19-
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
20-
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
21-
"esModuleInterop": true,
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"target": "es2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
5+
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
6+
"skipLibCheck": true,
7+
// "lib": [], /* Specify library files to be included in the compilation: */
8+
// "allowJs": true, /* Allow javascript files to be compiled. */
9+
// "checkJs": true, /* Report errors in .js files. */
10+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
11+
"declaration": true, /* Generates corresponding '.d.ts' file. */
12+
// "sourceMap": true, /* Generates corresponding '.map' file. */
13+
// "outFile": "./", /* Concatenate and emit output to single file. */
14+
"outDir": "./dist", /* Redirect output structure to the directory. */
15+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
16+
// "removeComments": true, /* Do not emit comments to output. */
17+
// "noEmit": true, /* Do not emit outputs. */
18+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
19+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
20+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
21+
"esModuleInterop": true,
2222

23-
/* Strict Type-Checking Options */
24-
"strict": false, /* Enable all strict type-checking options. */
25-
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
26-
// "strictNullChecks": true, /* Enable strict null checks. */
27-
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
28-
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
23+
/* Strict Type-Checking Options */
24+
"strict": false, /* Enable all strict type-checking options. */
25+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
26+
// "strictNullChecks": true, /* Enable strict null checks. */
27+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
28+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
2929

30-
/* Additional Checks */
31-
// "noUnusedLocals": true, /* Report errors on unused locals. */
32-
// "noUnusedParameters": true, /* Report errors on unused parameters. */
33-
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
34-
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
30+
/* Additional Checks */
31+
// "noUnusedLocals": true, /* Report errors on unused locals. */
32+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
33+
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
34+
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
3535

36-
/* Module Resolution Options */
37-
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
38-
"baseUrl": "./src", /* Base directory to resolve non-absolute module names. */
39-
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
40-
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
41-
// "typeRoots": [], /* List of folders to include type definitions from. */
42-
// "types": [], /* Type declaration files to be included in compilation. */
43-
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
36+
/* Module Resolution Options */
37+
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
38+
"baseUrl": "./src", /* Base directory to resolve non-absolute module names. */
39+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
40+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
41+
// "typeRoots": [], /* List of folders to include type definitions from. */
42+
// "types": [], /* Type declaration files to be included in compilation. */
43+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
4444

45-
/* Source Map Options */
46-
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
47-
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
48-
"inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
49-
"inlineSources": true /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
45+
/* Source Map Options */
46+
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
47+
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
48+
"inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
49+
"inlineSources": true /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
5050

51-
/* Experimental Options */
52-
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
53-
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
54-
},
55-
"include": [
56-
"src/**/*.ts"
57-
],
58-
"types": [
59-
"n-readlines"
60-
]
61-
}
51+
/* Experimental Options */
52+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
53+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
54+
},
55+
"include": [
56+
"src/**/*.ts"
57+
],
58+
"types": [
59+
"n-readlines"
60+
]
61+
}

0 commit comments

Comments
 (0)