Skip to content

Commit

Permalink
Migrate from tslint to eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Jan 27, 2022
1 parent c3485c2 commit 97a24a3
Show file tree
Hide file tree
Showing 19 changed files with 1,148 additions and 688 deletions.
224 changes: 224 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"sourceType": "module"
},
"plugins": [
"eslint-plugin-import",
"eslint-plugin-jsdoc",
"eslint-plugin-unicorn",
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": [
"error",
{
"default": "array"
}
],
"@typescript-eslint/ban-types": [
"error",
{
"types": {
"Object": {
"message": "Avoid using the `Object` type. Did you mean `object`?"
},
"Function": {
"message": "Avoid using the `Function` type. Prefer a specific function type, like `() => void`."
},
"Boolean": {
"message": "Avoid using the `Boolean` type. Did you mean `boolean`?"
},
"Number": {
"message": "Avoid using the `Number` type. Did you mean `number`?"
},
"String": {
"message": "Avoid using the `String` type. Did you mean `string`?"
},
"Symbol": {
"message": "Avoid using the `Symbol` type. Did you mean `symbol`?"
}
}
}
],
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/dot-notation": "error",
"@typescript-eslint/indent": [
"error",
2,
{
"ObjectExpression": "first",
"FunctionDeclaration": {
"parameters": "first"
},
"FunctionExpression": {
"parameters": "first"
},
"SwitchCase": 1
}
],
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-empty-function": [
"error",
{
"allow": [
"constructors"
]
}
],
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-shadow": [
"error",
{
"hoist": "all"
}
],
"@typescript-eslint/no-this-alias": "error",
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "off",
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/quotes": "off",
"@typescript-eslint/semi": [
"error",
"always"
],
"@typescript-eslint/triple-slash-reference": [
"error",
{
"path": "always",
"types": "prefer-import",
"lib": "always"
}
],
"@typescript-eslint/unified-signatures": "error",
"arrow-parens": [
"error",
"as-needed"
],
"comma-dangle": "error",
"complexity": "off",
"constructor-super": "error",
"curly": "off",
"default-case": "off",
"dot-notation": "error",
"eqeqeq": [
"error",
"smart"
],
"guard-for-in": "off",
"id-denylist": [
"error",
"any",
"Number",
"number",
"String",
"string",
"Boolean",
"boolean",
"Undefined",
"undefined"
],
"id-match": "error",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": false
}
],
"import/no-internal-modules": "off",
"import/order": "off",
"indent": "off",
"jsdoc/check-alignment": "error",
"jsdoc/check-indentation": "error",
"jsdoc/newline-after-description": [
"error",
"never"
],
"max-classes-per-file": "off",
"max-len": [
"error",
{
"code": 200
}
],
"new-parens": "error",
"no-bitwise": "off",
"no-caller": "error",
"no-cond-assign": "error",
"no-console": "error",
"no-debugger": "error",
"no-duplicate-case": "error",
"no-duplicate-imports": "error",
"no-empty": "error",
"no-empty-function": "off",
"no-eval": "error",
"no-extra-bind": "error",
"no-fallthrough": "off",
"no-invalid-this": "off",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-redeclare": "error",
"no-return-await": "error",
"no-sequences": "error",
"no-shadow": "error",
"no-sparse-arrays": "error",
"no-template-curly-in-string": "error",
"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",
"no-use-before-define": "off",
"no-var": "error",
"object-shorthand": "error",
"one-var": [
"error",
"never"
],
"prefer-const": "error",
"prefer-object-spread": "error",
"quote-props": [
"error",
"as-needed"
],
"quotes": "off",
"radix": "error",
"semi": "error",
"space-in-parens": [
"error",
"never"
],
"spaced-comment": [
"error",
"always",
{
"markers": [
"/"
]
}
],
"unicorn/prefer-ternary": "error",
"use-isnan": "error",
"valid-typeof": "off"
}
}

8 changes: 8 additions & 0 deletions example/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
ESLint configuration
*/
{
"rules": {
"no-console": "off"
}
}
18 changes: 9 additions & 9 deletions lib/ParserFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ export function parseHttpContentType(contentType: string): { type: string, subty
};
}

async function parse(tokenizer: ITokenizer, parserId: ParserType, opts: IOptions = {}): Promise<IAudioMetadata> {
// Parser found, execute parser
const parser = await ParserFactory.loadParser(parserId);
const metadata = new MetadataCollector(opts);
await parser.init(metadata, tokenizer, opts).parse();
return metadata.toCommonMetadata();
}

export class ParserFactory {

/**
Expand Down Expand Up @@ -97,7 +105,7 @@ export class ParserFactory {
}
}
// Parser found, execute parser
return this._parse(tokenizer, parserId, opts);
return parse(tokenizer, parserId, opts);
}

/**
Expand Down Expand Up @@ -199,14 +207,6 @@ export class ParserFactory {
}
}

private static async _parse(tokenizer: ITokenizer, parserId: ParserType, opts: IOptions = {}): Promise<IAudioMetadata> {
// Parser found, execute parser
const parser = await ParserFactory.loadParser(parserId);
const metadata = new MetadataCollector(opts);
await parser.init(metadata, tokenizer, opts).parse();
return metadata.toCommonMetadata();
}

private static getExtension(fname: string): string {
const i = fname.lastIndexOf('.');
return i === -1 ? '' : fname.slice(i);
Expand Down
3 changes: 1 addition & 2 deletions lib/apev2/APEv2Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,10 @@ export class APEv2Parser extends BasicParser {
bytesRemaining -= key.length + 1;

switch (tagItemHeader.flags.dataType) {
case DataType.text_utf8: { // utf-8 textstring
case DataType.text_utf8: { // utf-8 text-string
const value = await this.tokenizer.readToken<string>(new StringType(tagItemHeader.size, 'utf8'));
const values = value.split(/\x00/g);

/*jshint loopfunc:true */
for (const val of values) {
this.metadata.addTag(tagFormat, key, val);
}
Expand Down
13 changes: 3 additions & 10 deletions lib/type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { GenericTagId, TagType } from './common/GenericTagTypes';
import { IFooter } from './apev2/APEv2Token';
import { TrackType } from './matroska/types';

export { TrackType } from './matroska/types';

/**
* Attached picture, typically used for cover art
Expand Down Expand Up @@ -402,16 +405,6 @@ export interface IVideoTrack {
gammaValue?: number;
}

export enum TrackType {
video = 0x01,
audio = 0x02,
complex = 0x03,
logo = 0x04,
subtitle = 0x11,
button = 0x12,
control = 0x20
}

export interface ITrackInfo {
type?: TrackType;
codecName?: string;
Expand Down
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
"compile-test": "tsc -p test",
"compile-doc": "tsc -p doc-gen",
"compile": "npm run compile-src && npm run compile-test && npm run compile-doc",
"lint-ts": "tslint 'lib/**/*.ts' 'example/typescript/*.ts' --exclude 'lib/**/*.d.ts' 'test/**/*.ts' --exclude 'test/**/*.d.ts' 'doc-gen/**/*.ts'",
"eslint": "eslint lib/*.ts --ignore-pattern lib/*.d.ts example/typescript/*.ts test/*.ts doc-gen/*.ts",
"lint-md": "remark -u preset-lint-recommended .",
"lint": "npm run lint-md && npm run lint-ts",
"lint": "npm run lint-md && npm run eslint",
"test": "mocha --require ts-node/register --require source-map-support/register --full-trace test/test-*.ts",
"build": "npm run clean && npm run compile && npm run doc-gen",
"start": "npm-run-all compile lint cover-test",
Expand All @@ -97,19 +97,25 @@
"@types/file-type": "^10.9.1",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.12",
"@typescript-eslint/eslint-plugin": "^5.10.1",
"@typescript-eslint/parser": "^5.10.1",
"chai": "^4.3.6",
"coveralls": "^3.1.1",
"del-cli": "4.0.1",
"eslint": "8.7.0",
"eslint": "^8.7.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsdoc": "^37.7.0",
"eslint-plugin-unicorn": "^40.1.0",
"mime": "^3.0.0",
"mocha": "^9.2.0",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"prettier": "^2.5.1",
"remark-cli": "^10.0.1",
"remark-preset-lint-recommended": "^6.1.2",
"source-map-support": "^0.5.21",
"ts-node": "^10.3.0",
"tslint": "^6.1.3",
"typescript": "^4.5.5"
},
"engines": {
Expand Down
14 changes: 14 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
ESLint configuration
*/

{
"rules": {
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
]
}
}
4 changes: 3 additions & 1 deletion test/test-file-mp3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ describe('Parse MP3 files', () => {
assert.strictEqual(common.album, 'Sanctuary', 'common.album');
assert.strictEqual(common.year, 2005, 'common.year');

assert.includeDeepMembers(quality.warnings, [{message: 'id3v2.3 type=TLEN header has invalid string value: Expected even number of octets for 16-bit unicode string'}], 'Warning on invalid TLEN field');
assert.includeDeepMembers(quality.warnings, [{
message: 'id3v2.3 type=TLEN header has invalid string value: Expected even number of octets for 16-bit unicode string'}],
'Warning on invalid TLEN field');
});

// https://github.com/Borewit/music-metadata/issues/430
Expand Down
Loading

0 comments on commit 97a24a3

Please sign in to comment.