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"], "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"rules": { "rules": {
"@typescript-eslint/no-unused-vars": ["warn", { "varsIgnorePattern": "_" }], "@typescript-eslint/no-unused-vars": ["warn", { "varsIgnorePattern": "_" }],
"@typescript-eslint/no-inferrable-types": ["off"], "@typescript-eslint/no-inferrable-types": ["off"]
"@typescript-eslint/ban-ts-comment": ["warn"]
} }
} }

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
import { Context, Recogniser } from '.'; 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 * 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'; return 'UTF-16BE';
} }
match(det: Context) { match(det: Context): Match | null {
const input = det.fRawInput; const input = det.fRawInput;
if ( if (
@ -30,7 +30,7 @@ export class UTF_16LE implements Recogniser {
name() { name() {
return 'UTF-16LE'; return 'UTF-16LE';
} }
match(det: Context) { match(det: Context): Match | null {
const input = det.fRawInput; const input = det.fRawInput;
if ( if (
@ -64,7 +64,7 @@ class UTF_32 implements Recogniser, WithGetChar {
return -1; return -1;
} }
match(det: Context) { match(det: Context): Match | null {
let numValid = 0, let numValid = 0,
numInvalid = 0, numInvalid = 0,
hasBOM = false, hasBOM = false,

View File

@ -1,12 +1,12 @@
import { Context, Recogniser } from '.'; import { Context, Recogniser } from '.';
const match = require('../match').default; import match, { Match } from '../match';
export default class Utf8 implements Recogniser { export default class Utf8 implements Recogniser {
name() { name() {
return 'UTF-8'; return 'UTF-8';
} }
match(det: Context) { match(det: Context): Match | null {
let hasBOM = false, let hasBOM = false,
numValid = 0, numValid = 0,
numInvalid = 0, numInvalid = 0,
@ -42,7 +42,7 @@ export default class Utf8 implements Recogniser {
} }
// Verify that we've got the right number of trail bytes in the sequence // Verify that we've got the right number of trail bytes in the sequence
for (;;) { for (; ;) {
i++; i++;
if (i >= det.fRawLength) break; if (i >= det.fRawLength) break;

View File

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