chore: fix linting errors

This commit is contained in:
Dmitry Shirokov 2020-09-23 13:06:43 +10:00
parent f2aa0dc231
commit 5d99fd5252
No known key found for this signature in database
GPG Key ID: 0D8CF8C72764BA46
7 changed files with 21 additions and 28 deletions

View File

@ -5,7 +5,6 @@
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"rules": {
"@typescript-eslint/no-unused-vars": ["warn", { "varsIgnorePattern": "_" }],
"@typescript-eslint/no-inferrable-types": ["off"],
"@typescript-eslint/ban-ts-comment": ["warn"]
"@typescript-eslint/no-inferrable-types": ["off"]
}
}

View File

@ -1,6 +1,5 @@
import { Context, Recogniser } from '.';
const match = require('../match').default;
import match, { Match } from '../match'
/**
* This is a superclass for the individual detectors for
@ -15,7 +14,7 @@ class ISO_2022 implements Recogniser {
return 'ISO_2022';
}
match(det: Context) {
match(det: Context): Match | null {
/**
* Matching function shared among the 2022 detectors JP, CN and KR
* Counts up the number of legal an unrecognized escape sequences in

View File

@ -1,5 +1,5 @@
import { Context, Recogniser } from '.';
const match = require('../match').default;
import match, { Match } from '../match'
/**
* Binary search implementation (recursive)
@ -97,7 +97,7 @@ class mbcs implements Recogniser {
* bits 0-7: the match confidence, ranging from 0-100
* bits 8-15: The match reason, an enum-like value.
*/
match(det: Context) {
match(det: Context): Match | null {
let singleByteCharCount = 0, //TODO Do we really need this?
doubleByteCharCount = 0,
commonCharCount = 0,
@ -159,7 +159,7 @@ class mbcs implements Recogniser {
}
if (this.commonChars == null) {
// We have no statistics on frequently occuring characters.
// We have no statistics on frequently occurring characters.
// Assess confidence purely on having a reasonable number of
// multi-byte characters (the more the better
confidence = 30 + doubleByteCharCount - 20 * badCharCount;
@ -167,11 +167,8 @@ class mbcs implements Recogniser {
confidence = 100;
}
} else {
//
// Frequency of occurrence statistics exist.
//
// @ts-ignore
const maxVal = Math.log(parseFloat(doubleByteCharCount) / 4);
const maxVal = Math.log(doubleByteCharCount / 4);
const scaleFactor = 90.0 / maxVal;
confidence = Math.floor(
Math.log(commonCharCount + 1) * scaleFactor + 10

View File

@ -1,6 +1,5 @@
import { Context, Recogniser } from '../encoding/index';
const match = require('../match').default;
import match, { Match } from '../match';
/**
* This class recognizes single-byte encodings. Because the encoding scheme is so
@ -119,12 +118,11 @@ class sbcs implements Recogniser {
return [];
}
// @ts-ignore
name(input: Context): string {
return 'sbcs';
}
match(det: Context) {
match(det: Context): Match | null {
const ngrams = this.ngrams();
if (isFlatNgrams(ngrams)) {
@ -134,7 +132,7 @@ class sbcs implements Recogniser {
}
let bestConfidenceSoFar = -1;
let lang = null;
let lang;
for (let i = ngrams.length - 1; i >= 0; i--) {
const ngl = ngrams[i];

View File

@ -1,5 +1,5 @@
import { Context, Recogniser } from '.';
const match = require('../match').default;
import match, { Match } from '../match';
/**
* This class matches UTF-16 and UTF-32, both big- and little-endian. The
@ -10,7 +10,7 @@ export class UTF_16BE implements Recogniser {
return 'UTF-16BE';
}
match(det: Context) {
match(det: Context): Match | null {
const input = det.fRawInput;
if (
@ -30,7 +30,7 @@ export class UTF_16LE implements Recogniser {
name() {
return 'UTF-16LE';
}
match(det: Context) {
match(det: Context): Match | null {
const input = det.fRawInput;
if (
@ -64,7 +64,7 @@ class UTF_32 implements Recogniser, WithGetChar {
return -1;
}
match(det: Context) {
match(det: Context): Match | null {
let numValid = 0,
numInvalid = 0,
hasBOM = false,

View File

@ -1,12 +1,12 @@
import { Context, Recogniser } from '.';
const match = require('../match').default;
import match, { Match } from '../match';
export default class Utf8 implements Recogniser {
name() {
return 'UTF-8';
}
match(det: Context) {
match(det: Context): Match | null {
let hasBOM = false,
numValid = 0,
numInvalid = 0,

View File

@ -1,12 +1,12 @@
import { Context, Recogniser } from "./encoding";
export interface Match {
confidence: number;
name: string;
lang: string;
lang?: string;
}
// @ts-ignore
export default (det, rec, confidence, name, lang): Match => ({
export default (det: Context, rec: Recogniser, confidence: number, name?: string, lang?: string): Match => ({
confidence,
name: name || rec.name(det),
lang,