├── .prettierignore ├── .eslintignore ├── .gitignore ├── test-workspace ├── packages │ ├── project2 │ │ ├── index.ts │ │ └── tsconfig.json │ ├── project3 │ │ ├── index.ts │ │ └── tsconfig.json │ └── project1 │ │ ├── index.ts │ │ └── tsconfig.json ├── package.json └── package-lock.json ├── docs └── diagnostics.png ├── Changelog.md ├── .prettierc.json ├── .editorconfig ├── src ├── tstl.d.ts └── index.ts ├── .github └── workflows │ ├── ci.yml │ └── release.yml ├── tsconfig.json ├── README.md ├── package.json ├── .eslintrc.js └── LICENSE /.prettierignore: -------------------------------------------------------------------------------- 1 | /lib 2 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | /lib 2 | /test-workspace 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | /lib 3 | .vscode 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /test-workspace/packages/project2/index.ts: -------------------------------------------------------------------------------- 1 | const x = 1 | 2; 2 | -------------------------------------------------------------------------------- /test-workspace/packages/project3/index.ts: -------------------------------------------------------------------------------- 1 | const x = 1 | 2; 2 | -------------------------------------------------------------------------------- /docs/diagnostics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TypeScriptToLua/typescript-tstl-plugin/HEAD/docs/diagnostics.png -------------------------------------------------------------------------------- /Changelog.md: -------------------------------------------------------------------------------- 1 | # 0.3.0 2 | 3 | - Dropped support for TSTL version `0.35.0` 4 | - Dropped support for TS versions `3.X` 5 | -------------------------------------------------------------------------------- /test-workspace/packages/project1/index.ts: -------------------------------------------------------------------------------- 1 | const x = 1 | 2; 2 | 3 | async function a() { 4 | return 42; 5 | } 6 | await a(); 7 | export {}; 8 | -------------------------------------------------------------------------------- /test-workspace/packages/project3/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "plugins": [{ "name": "typescript-tstl-plugin" }] 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.prettierc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "tabWidth": 4, 4 | "arrowParens": "avoid", 5 | "overrides": [{ "files": ["**/*.md", "**/*.yml"], "options": { "tabWidth": 2 } }] 6 | } 7 | -------------------------------------------------------------------------------- /test-workspace/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "devDependencies": { 4 | "typescript-to-lua": "../node_modules/typescript-to-lua", 5 | "typescript-tstl-plugin": ".." 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test-workspace/packages/project1/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "plugins": [{ "name": "typescript-tstl-plugin" }] 4 | }, 5 | "tstl": { 6 | "luaTarget": "5.1" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test-workspace/packages/project2/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "plugins": [{ "name": "typescript-tstl-plugin" }] 4 | }, 5 | "tstl": { 6 | "luaTarget": "5.2" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /src/tstl.d.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-unnecessary-qualifier */ 2 | import * as tstl from 'typescript-to-lua'; 3 | 4 | declare module 'typescript-to-lua' { 5 | export const transpile: ((options: tstl.TranspileOptions) => tstl.TranspileResult) | undefined; 6 | } 7 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | main: 7 | name: Main 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Use Node.js 12.13.1 13 | uses: actions/setup-node@v1 14 | with: 15 | node-version: 12.13.1 16 | - run: npm ci 17 | - run: npm run build 18 | - run: npm run lint 19 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | tags: '*' 6 | 7 | jobs: 8 | release: 9 | name: Release 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v2 14 | - name: Use Node.js 12.13.1 15 | uses: actions/setup-node@v1 16 | with: 17 | node-version: 12.13.1 18 | registry-url: 'https://registry.npmjs.org' 19 | - run: npm ci 20 | - run: npm run build 21 | - run: npm publish 22 | env: 23 | NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} 24 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": ["src"], 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./lib", 6 | "moduleResolution": "Node", 7 | "module": "commonjs", 8 | "resolveJsonModule": true, 9 | "downlevelIteration": true, 10 | "importHelpers": true, 11 | "newLine": "LF", 12 | "types": ["node"], 13 | "allowSyntheticDefaultImports": true, 14 | "esModuleInterop": true, 15 | "strict": true, 16 | "noUnusedLocals": true, 17 | "noUnusedParameters": true, 18 | "target": "es2020", 19 | "lib": ["es2020"], 20 | "sourceMap": true, 21 | "declaration": true, 22 | "declarationMap": true 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TypeScript TypeScriptToLua Language Service plugin 2 | 3 | TypeScript Language Service plugin for [TypeScriptToLua](https://typescripttolua.github.io). 4 | 5 | ## Installation 6 | 7 | The simplest way to use this plugin in Visual Studio Code is to install the 8 | [extension](https://marketplace.visualstudio.com/items?itemName=ark120202.vscode-typescript-to-lua). 9 | 10 | For other editors that use TypeScript Language Service you can enable this plugin manually: 11 | 12 | ```shell 13 | npm install typescript-tstl-plugin 14 | ``` 15 | 16 | tsconfig.json: 17 | 18 | ```jsonc 19 | { 20 | "compilerOptions": { 21 | "plugins": [{ "name": "typescript-tstl-plugin" }] 22 | }, 23 | "tstl": { 24 | // "tstl" key is required 25 | } 26 | } 27 | ``` 28 | 29 | ## Features 30 | 31 | Currently the only feature this plugin implements is displaying TypeScriptToLua diagnostics: 32 | 33 | ![](/docs/diagnostics.png) 34 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "typescript-tstl-plugin", 3 | "version": "0.3.2", 4 | "description": "TypeScript TypeScriptToLua Language Service plugin", 5 | "keywords": [ 6 | "typescript" 7 | ], 8 | "repository": "https://github.com/TypeScriptToLua/typescript-tstl-plugin", 9 | "license": "Apache-2.0", 10 | "author": "ark120202", 11 | "files": [ 12 | "lib/**/*.js", 13 | "lib/**/*.ts" 14 | ], 15 | "main": "lib/index.js", 16 | "types": "lib/index.d.ts", 17 | "scripts": { 18 | "build": "tsc", 19 | "dev": "tsc --watch", 20 | "lint": "run-s lint:prettier lint:eslint", 21 | "lint:eslint": "eslint . --ext .ts", 22 | "lint:prettier": "prettier --check .", 23 | "fix:prettier": "prettier --write .", 24 | "prepublishOnly": "npm run build", 25 | "preversion": "npm run build", 26 | "postversion": "git push && git push --tags" 27 | }, 28 | "prettier": { 29 | "printWidth": 100, 30 | "proseWrap": "always", 31 | "singleQuote": true, 32 | "trailingComma": "all" 33 | }, 34 | "dependencies": { 35 | "mock-require": "^3.0.3", 36 | "resolve-from": "^5.0.0", 37 | "resolve-global": "^1.0.0", 38 | "tslib": "^1.14.1", 39 | "typescript-to-lua": "^0.36.0" 40 | }, 41 | "devDependencies": { 42 | "@types/mock-require": "^2.0.0", 43 | "@types/node": "^14.0.23", 44 | "@typescript-eslint/eslint-plugin": "^4.29.3", 45 | "@typescript-eslint/parser": "^4.2.0", 46 | "eslint": "^7.28.0", 47 | "eslint-config-prettier": "^6.9.0", 48 | "npm-run-all": "^4.1.5", 49 | "prettier": "^2.0.5", 50 | "typescript": "^4.3.5" 51 | }, 52 | "engines": { 53 | "node": ">=12.13.0" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /test-workspace/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-workspace", 3 | "lockfileVersion": 2, 4 | "requires": true, 5 | "packages": { 6 | "": { 7 | "devDependencies": { 8 | "typescript-to-lua": "../node_modules/typescript-to-lua", 9 | "typescript-tstl-plugin": ".." 10 | } 11 | }, 12 | "..": { 13 | "version": "0.2.0", 14 | "dev": true, 15 | "license": "Apache-2.0", 16 | "dependencies": { 17 | "mock-require": "^3.0.3", 18 | "resolve-from": "^5.0.0", 19 | "resolve-global": "^1.0.0", 20 | "typescript-to-lua": "^0.36.0" 21 | }, 22 | "devDependencies": { 23 | "@types/mock-require": "^2.0.0", 24 | "@types/node": "^14.0.23", 25 | "@typescript-eslint/eslint-plugin": "^4.29.3", 26 | "@typescript-eslint/parser": "^4.2.0", 27 | "eslint": "^7.28.0", 28 | "eslint-config-prettier": "^6.9.0", 29 | "npm-run-all": "^4.1.5", 30 | "prettier": "^2.0.5", 31 | "typescript": "^4.3.5" 32 | }, 33 | "engines": { 34 | "node": ">=12.13.0" 35 | } 36 | }, 37 | "../node_modules/typescript-to-lua": { 38 | "version": "0.36.1", 39 | "dev": true, 40 | "license": "MIT", 41 | "dependencies": { 42 | "resolve": "^1.15.1", 43 | "source-map": "^0.7.3", 44 | "typescript": ">=4.0.2" 45 | }, 46 | "bin": { 47 | "tstl": "dist/tstl.js" 48 | }, 49 | "engines": { 50 | "node": ">=12.13.0" 51 | } 52 | }, 53 | "node_modules/typescript-to-lua": { 54 | "resolved": "../node_modules/typescript-to-lua", 55 | "link": true 56 | }, 57 | "node_modules/typescript-tstl-plugin": { 58 | "resolved": "..", 59 | "link": true 60 | } 61 | }, 62 | "dependencies": { 63 | "typescript-to-lua": { 64 | "version": "file:../node_modules/typescript-to-lua", 65 | "requires": { 66 | "@types/fs-extra": "^8.1.0", 67 | "@types/glob": "^7.1.1", 68 | "@types/jest": "^25.1.3", 69 | "@types/node": "^13.7.7", 70 | "@types/resolve": "1.14.0", 71 | "@typescript-eslint/eslint-plugin": "^2.31.0", 72 | "@typescript-eslint/parser": "^4.1.0", 73 | "eslint": "^6.8.0", 74 | "eslint-plugin-import": "^2.20.1", 75 | "eslint-plugin-jest": "^23.8.2", 76 | "fengari": "^0.1.4", 77 | "fs-extra": "^8.1.0", 78 | "javascript-stringify": "^2.0.1", 79 | "jest": "^26.0.1", 80 | "jest-circus": "^25.1.0", 81 | "lua-types": "^2.8.0", 82 | "prettier": "^2.0.5", 83 | "resolve": "^1.15.1", 84 | "source-map": "^0.7.3", 85 | "ts-jest": "^26.3.0", 86 | "ts-node": "^8.6.2", 87 | "typescript": ">=4.0.2" 88 | } 89 | }, 90 | "typescript-tstl-plugin": { 91 | "version": "file:..", 92 | "requires": { 93 | "@types/mock-require": "^2.0.0", 94 | "@types/node": "^14.0.23", 95 | "@typescript-eslint/eslint-plugin": "^4.29.3", 96 | "@typescript-eslint/parser": "^4.2.0", 97 | "eslint": "^7.28.0", 98 | "eslint-config-prettier": "^6.9.0", 99 | "mock-require": "^3.0.3", 100 | "npm-run-all": "^4.1.5", 101 | "prettier": "^2.0.5", 102 | "resolve-from": "^5.0.0", 103 | "resolve-global": "^1.0.0", 104 | "typescript": "^4.3.5", 105 | "typescript-to-lua": "^0.36.0" 106 | }, 107 | "dependencies": { 108 | "typescript-to-lua": { 109 | "version": "0.36.1", 110 | "dev": true, 111 | "requires": { 112 | "@types/fs-extra": "^8.1.0", 113 | "@types/glob": "^7.1.1", 114 | "@types/jest": "^25.1.3", 115 | "@types/node": "^13.7.7", 116 | "@types/resolve": "1.14.0", 117 | "@typescript-eslint/eslint-plugin": "^2.31.0", 118 | "@typescript-eslint/parser": "^4.1.0", 119 | "eslint": "^6.8.0", 120 | "eslint-plugin-import": "^2.20.1", 121 | "eslint-plugin-jest": "^23.8.2", 122 | "fengari": "^0.1.4", 123 | "fs-extra": "^8.1.0", 124 | "javascript-stringify": "^2.0.1", 125 | "jest": "^26.0.1", 126 | "jest-circus": "^25.1.0", 127 | "lua-types": "^2.8.0", 128 | "prettier": "^2.0.5", 129 | "resolve": "^1.15.1", 130 | "source-map": "^0.7.3", 131 | "ts-jest": "^26.3.0", 132 | "ts-node": "^8.6.2", 133 | "typescript": ">=4.0.2" 134 | } 135 | } 136 | } 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import mockRequire from 'mock-require'; 2 | import path from 'path'; 3 | import resolveFrom from 'resolve-from'; 4 | import resolveGlobal from 'resolve-global'; 5 | import type * as tstl from 'typescript-to-lua'; 6 | import type * as tsserverlibrary from 'typescript/lib/tsserverlibrary'; 7 | 8 | const pluginMarker = Symbol('pluginMarker'); 9 | class TSTLPlugin { 10 | constructor( 11 | private readonly ts: typeof tsserverlibrary, 12 | private readonly languageService: tsserverlibrary.LanguageService, 13 | private readonly project: tsserverlibrary.server.Project, 14 | private readonly serverHost: tsserverlibrary.server.ServerHost, 15 | ) {} 16 | 17 | private log(message: string) { 18 | this.project.log(`[typescript-tstl-plugin] ${this.project.getProjectName()}: ${message}`); 19 | } 20 | 21 | private parsedCommandLine?: tstl.ParsedCommandLine; 22 | public update() { 23 | this.log('Updating project'); 24 | if (!(this.project instanceof this.ts.server.ConfiguredProject)) return; 25 | 26 | const configFilePath = this.project.getConfigFilePath(); 27 | const config = this.ts.parseJsonSourceFileConfigFileContent( 28 | this.ts.readJsonConfigFile(configFilePath, this.serverHost.readFile), 29 | this.serverHost, 30 | path.dirname(configFilePath), 31 | undefined, 32 | configFilePath, 33 | ); 34 | this.parsedCommandLine = this.tstl.updateParsedConfigFile(config); 35 | } 36 | 37 | private _tstl?: typeof import('typescript-to-lua'); 38 | private get tstl() { 39 | if (!this._tstl) { 40 | const resolved = 41 | resolveFrom.silent(this.project.getCurrentDirectory(), 'typescript-to-lua') || 42 | resolveGlobal.silent('typescript-to-lua') || 43 | 'typescript-to-lua'; 44 | 45 | this.log(`Loading typescript-to-lua from "${resolved}"`); 46 | // eslint-disable-next-line @typescript-eslint/no-require-imports 47 | this._tstl = require(resolved); 48 | } 49 | 50 | return this._tstl!; 51 | } 52 | 53 | public wrap() { 54 | this.log('Wrapping language service'); 55 | this.update(); 56 | 57 | const intercept: Partial = Object.create(null); 58 | (intercept as any)[pluginMarker] = this; 59 | intercept.getSemanticDiagnostics = this.getSemanticDiagnostics.bind(this); 60 | return new Proxy(this.languageService, { 61 | get: (target, property) => (intercept as any)[property] || (target as any)[property], 62 | }); 63 | } 64 | 65 | private getSemanticDiagnostics(fileName: string) { 66 | const diagnostics = this.languageService.getSemanticDiagnostics(fileName); 67 | const program = this.languageService.getProgram(); 68 | if (!program) return diagnostics; 69 | 70 | const sourceFile = program.getSourceFile(fileName); 71 | if (sourceFile && !sourceFile.isDeclarationFile) { 72 | diagnostics.push(...this.getTstlDiagnostics(program, sourceFile)); 73 | } 74 | 75 | return diagnostics; 76 | } 77 | 78 | private getTstlDiagnostics( 79 | program: tsserverlibrary.Program, 80 | sourceFile: tsserverlibrary.SourceFile, 81 | ) { 82 | if (this.parsedCommandLine?.raw.tstl != null) { 83 | const programOptions = program.getCompilerOptions(); 84 | Object.assign(programOptions, this.parsedCommandLine.options); 85 | programOptions.noEmit = true; 86 | programOptions.noEmitOnError = false; 87 | programOptions.declaration = false; 88 | programOptions.declarationMap = false; 89 | programOptions.emitDeclarationOnly = false; 90 | 91 | try { 92 | let diagnostics: tsserverlibrary.Diagnostic[] | undefined; 93 | 94 | // >=0.35.0 95 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition 96 | if (this.tstl.getProgramTranspileResult !== undefined) { 97 | ({ diagnostics } = this.tstl.getProgramTranspileResult(this.serverHost, () => {}, { 98 | program, 99 | sourceFiles: [sourceFile], 100 | })); 101 | } 102 | 103 | // >=0.19.0 104 | if (this.tstl.transpile !== undefined) { 105 | ({ diagnostics } = this.tstl.transpile({ program, sourceFiles: [sourceFile] })); 106 | } 107 | 108 | if (diagnostics === undefined) { 109 | throw new Error(`Unsupported TypeScriptToLua version: ${this.tstl.version}`); 110 | } 111 | 112 | return diagnostics.map((diag) => ({ ...diag, code: undefined! })); 113 | } catch (error) { 114 | this.log(`Error during transpilation: ${error.stack}`); 115 | } 116 | } 117 | 118 | return []; 119 | } 120 | } 121 | 122 | const init: tsserverlibrary.server.PluginModuleFactory = ({ typescript }) => { 123 | mockRequire('typescript', typescript); 124 | 125 | return { 126 | create({ languageService, project, serverHost }) { 127 | const oldPlugin: TSTLPlugin | undefined = (languageService as any)[pluginMarker]; 128 | if (oldPlugin) { 129 | oldPlugin.update(); 130 | return languageService; 131 | } 132 | 133 | const plugin = new TSTLPlugin(typescript, languageService, project, serverHost); 134 | return plugin.wrap(); 135 | }, 136 | }; 137 | }; 138 | 139 | export = init; 140 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | /** @type {import('eslint').Linter.Config} */ 2 | module.exports = { 3 | extends: [ 4 | 'plugin:@typescript-eslint/base', 5 | 'plugin:@typescript-eslint/eslint-recommended', 6 | 'prettier/@typescript-eslint', 7 | ], 8 | parserOptions: { 9 | warnOnUnsupportedTypeScriptVersion: false, 10 | project: 'tsconfig.json', 11 | }, 12 | rules: { 13 | // Covered by TypeScript 14 | 'no-unused-vars': 'off', 15 | 'no-use-before-define': 'off', 16 | // Extension Rules 17 | 'no-array-constructor': 'off', 18 | '@typescript-eslint/no-array-constructor': 'error', 19 | 'no-loop-func': 'off', 20 | '@typescript-eslint/no-loop-func': 'error', 21 | 'no-shadow': 'off', 22 | '@typescript-eslint/no-shadow': 'error', 23 | 'no-unused-expressions': 'off', 24 | '@typescript-eslint/no-unused-expressions': 'error', 25 | 'no-useless-constructor': 'off', 26 | '@typescript-eslint/no-useless-constructor': 'error', 27 | quotes: 'off', 28 | '@typescript-eslint/quotes': [ 29 | 'error', 30 | 'single', 31 | { avoidEscape: true, allowTemplateLiterals: false }, 32 | ], 33 | 34 | '@typescript-eslint/adjacent-overload-signatures': 'error', 35 | '@typescript-eslint/array-type': 'error', 36 | '@typescript-eslint/await-thenable': 'error', 37 | '@typescript-eslint/ban-types': [ 38 | 'error', 39 | { 40 | types: { 41 | object: false, 42 | '{}': false, 43 | Function: null, 44 | CallableFunction: { fixWith: '(...args: any[]) => any' }, 45 | NewableFunction: { fixWith: 'new (...args: any[]) => any' }, 46 | }, 47 | }, 48 | ], 49 | '@typescript-eslint/consistent-type-assertions': [ 50 | 'error', 51 | { assertionStyle: 'as', objectLiteralTypeAssertions: 'never' }, 52 | ], 53 | '@typescript-eslint/consistent-type-definitions': 'error', 54 | '@typescript-eslint/explicit-member-accessibility': [ 55 | 'error', 56 | { overrides: { constructors: 'no-public' } }, 57 | ], 58 | camelcase: 'off', 59 | '@typescript-eslint/naming-convention': [ 60 | 'error', 61 | { selector: 'default', format: ['camelCase'] }, 62 | 63 | // TODO: Allow PascalCase for constructable types 64 | // TODO: Allow any name for destructured values 65 | { selector: 'variableLike', format: null }, 66 | // { selector: 'variableLike', format: ['camelCase'] }, 67 | // { selector: 'variable', format: ['camelCase', 'UPPER_CASE'] }, 68 | // { selector: 'parameter', format: ['camelCase'], leadingUnderscore: 'allow' }, 69 | 70 | // TODO: https://github.com/typescript-eslint/typescript-eslint/issues/1712 71 | // TODO: https://github.com/typescript-eslint/typescript-eslint/issues/2244 72 | { selector: 'memberLike', format: null }, 73 | // TODO: Keep only one format 74 | { selector: 'enumMember', format: ['PascalCase', 'UPPER_CASE'] }, 75 | // TODO: Require `private _property`? 76 | // { selector: 'memberLike', modifiers: ['private'], format: ['camelCase'], leadingUnderscore: 'require' }, 77 | 78 | { selector: 'typeLike', format: ['PascalCase'] }, 79 | { 80 | selector: 'typeParameter', 81 | format: ['PascalCase'], 82 | custom: { regex: '^(T(\\d+|[A-Z][A-Za-z0-9]*)?|U|P|K|V)$', match: true }, 83 | }, 84 | { 85 | selector: 'interface', 86 | format: ['PascalCase'], 87 | custom: { regex: '^I[A-Z]', match: false }, 88 | }, 89 | ], 90 | '@typescript-eslint/no-empty-interface': 'error', 91 | '@typescript-eslint/no-extra-non-null-assertion': 'error', 92 | '@typescript-eslint/no-extraneous-class': 'error', 93 | '@typescript-eslint/no-floating-promises': 'error', 94 | '@typescript-eslint/no-for-in-array': 'error', 95 | '@typescript-eslint/no-inferrable-types': 'error', 96 | '@typescript-eslint/no-misused-new': 'error', 97 | 'no-async-promise-executor': 'off', 98 | '@typescript-eslint/no-misused-promises': 'error', 99 | '@typescript-eslint/no-namespace': 'error', 100 | 'global-require': 'off', 101 | '@typescript-eslint/no-require-imports': 'error', 102 | '@typescript-eslint/no-this-alias': 'error', 103 | 'no-throw-literal': 'off', 104 | '@typescript-eslint/no-throw-literal': 'error', 105 | 'no-constant-condition': 'off', 106 | '@typescript-eslint/no-unnecessary-condition': ['error', { allowConstantLoopConditions: true }], 107 | '@typescript-eslint/no-unnecessary-qualifier': 'error', 108 | '@typescript-eslint/no-unnecessary-type-arguments': 'error', 109 | '@typescript-eslint/no-unnecessary-type-assertion': 'error', 110 | // TODO: Enable instead of unicorn/no-for-loop after https://github.com/typescript-eslint/typescript-eslint/issues/702 111 | // '@typescript-eslint/prefer-for-of': 'off', 112 | '@typescript-eslint/prefer-function-type': 'error', 113 | '@typescript-eslint/prefer-includes': 'error', 114 | '@typescript-eslint/prefer-optional-chain': 'error', 115 | '@typescript-eslint/prefer-namespace-keyword': 'error', 116 | // TODO: https://github.com/typescript-eslint/typescript-eslint/issues/1265 117 | '@typescript-eslint/prefer-nullish-coalescing': 'off', 118 | '@typescript-eslint/prefer-readonly': 'error', 119 | '@typescript-eslint/prefer-string-starts-ends-with': 'error', 120 | '@typescript-eslint/promise-function-async': ['error', { checkArrowFunctions: false }], 121 | '@typescript-eslint/require-array-sort-compare': 'error', 122 | '@typescript-eslint/require-await': 'error', 123 | '@typescript-eslint/restrict-plus-operands': ['error', { checkCompoundAssignments: true }], 124 | // TODO: Allow any 125 | // '@typescript-eslint/restrict-template-expressions': 'error', 126 | 'no-return-await': 'off', 127 | // TODO: Always? 128 | '@typescript-eslint/return-await': 'error', 129 | '@typescript-eslint/triple-slash-reference': 'error', 130 | '@typescript-eslint/unified-signatures': 'error', 131 | }, 132 | overrides: [ 133 | { 134 | files: '**/*.d.ts', 135 | rules: { 136 | // This plugin doesn't handle `declare class A { constructor() }` 137 | 'prefer-class-properties/prefer-class-properties': 'off', 138 | }, 139 | }, 140 | ], 141 | }; 142 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------