>(Base: T) {
+ return class extends Base {
+ static getTags(): void {}
+ tags(): void {}
+ };
+}
+
+class Test extends WithTags(FooItem) {}
+
+const test = new Test();
+
+Test.getTags();
+test.tags();
+interface Foo {
+ a: string;
+ b: number;
+};
+
+interface Bar {
+ b: string;
+}
+
+interface Other {
+ totallyUnrelatedProperty: number;
+}
+
+let x = { a: '', b: '' };
+
+declare function f(x: Foo | Other): any;
+
+f(x);
+f({ a: '', b: '' })
+
+declare function g(x: Bar | Other): any;
+
+g(x);
+g({ a: '', b: '' })
+
+declare function h(x: Foo | Bar | Other): any;
+
+h(x);
+h({ a: '', b: '' })
+
+interface CatDog { cat: any, dog: any }
+interface ManBearPig { man: any, bear: any, pig: any }
+interface Platypus { platypus: any }
+
+type ExoticAnimal =
+ | CatDog
+ | ManBearPig
+ | Platypus;
+
+declare function addToZoo(animal: ExoticAnimal): void;
+
+addToZoo({ dog: "Barky McBarkface" });
+addToZoo({ man: "Manny", bear: "Coffee" });
+
+const manBeer = { man: "Manny", beer: "Coffee" };
+addToZoo({ man: "Manny", beer: "Coffee" });
+addToZoo(manBeer);
+interface I {
+}
+
+enum E {
+ Red, Green, Blue
+}
+
+function f() {
+ var a: any;
+ var n=3;
+ var s="";
+ var b=false;
+ var i:I;
+ var e:E;
+
+ n&&a;
+ n&&s;
+ n&&b;
+ n&&i;
+ n&&n;
+ n&&e;
+
+ s&&a;
+ s&&n;
+ s&&b;
+ s&&i;
+ s&&s;
+ s&&e;
+
+ a&&n;
+ a&&s;
+ a&&b;
+ a&&i;
+ a&&a;
+ a&&e;
+
+ i&&n;
+ i&&s;
+ i&&b;
+ i&&a;
+ i&&i;
+ i&&e;
+
+ e&&n;
+ e&&s;
+ e&&b;
+ e&&a;
+ e&&i;
+ e&&e;
+
+ n||a;
+ n||s;
+ n||b;
+ n||i;
+ n||n;
+ n||e;
+
+ s||a;
+ s||n;
+ s||b;
+ s||i;
+ s||s;
+ s||e;
+
+ a||n;
+ a||s;
+ a||b;
+ a||i;
+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i;
+ i-e;
+
+ e-n;
+ e-s;
+ e-b;
+ e-a;
+ e-i;
+ e-e;
+
+}
diff --git a/packages/benchmark/fixtures/no-empty-interface/.eslintrc.js b/packages/benchmark/fixtures/no-empty-interface/.eslintrc.js
new file mode 100644
index 000000000000..4eb332bf900d
--- /dev/null
+++ b/packages/benchmark/fixtures/no-empty-interface/.eslintrc.js
@@ -0,0 +1,14 @@
+module.exports = {
+ root: true,
+ plugins: ['@typescript-eslint'],
+ rules: {
+ '@typescript-eslint/no-empty-interface': 'error'
+ },
+ parser: '@typescript-eslint/parser',
+ parserOptions: {
+ sourceType: 'module',
+ ecmaFeatures: {
+ jsx: false
+ }
+ }
+};
diff --git a/packages/benchmark/fixtures/no-empty-interface/test1.ts b/packages/benchmark/fixtures/no-empty-interface/test1.ts
new file mode 100644
index 000000000000..fa0ebf3c5638
--- /dev/null
+++ b/packages/benchmark/fixtures/no-empty-interface/test1.ts
@@ -0,0 +1 @@
+interface Foo {}
diff --git a/packages/benchmark/fixtures/no-empty-interface/test2.ts b/packages/benchmark/fixtures/no-empty-interface/test2.ts
new file mode 100644
index 000000000000..fa0ebf3c5638
--- /dev/null
+++ b/packages/benchmark/fixtures/no-empty-interface/test2.ts
@@ -0,0 +1 @@
+interface Foo {}
diff --git a/packages/benchmark/fixtures/no-empty-interface/test3.ts b/packages/benchmark/fixtures/no-empty-interface/test3.ts
new file mode 100644
index 000000000000..fa0ebf3c5638
--- /dev/null
+++ b/packages/benchmark/fixtures/no-empty-interface/test3.ts
@@ -0,0 +1 @@
+interface Foo {}
diff --git a/packages/benchmark/fixtures/no-empty-interface/tslint.json b/packages/benchmark/fixtures/no-empty-interface/tslint.json
new file mode 100644
index 000000000000..366f38b35e96
--- /dev/null
+++ b/packages/benchmark/fixtures/no-empty-interface/tslint.json
@@ -0,0 +1,5 @@
+{
+ "rules": {
+ "no-empty-interface": true
+ }
+}
diff --git a/packages/benchmark/fixtures/restrict-plus-operands/.eslintrc.js b/packages/benchmark/fixtures/restrict-plus-operands/.eslintrc.js
new file mode 100644
index 000000000000..29e8d14c7e9d
--- /dev/null
+++ b/packages/benchmark/fixtures/restrict-plus-operands/.eslintrc.js
@@ -0,0 +1,16 @@
+module.exports = {
+ root: true,
+ plugins: ['@typescript-eslint'],
+ rules: {
+ '@typescript-eslint/restrict-plus-operands': 'error'
+ },
+ parser: '@typescript-eslint/parser',
+ parserOptions: {
+ tsconfigRootDir: __dirname,
+ project: './tsconfig.json',
+ sourceType: 'module',
+ ecmaFeatures: {
+ jsx: false
+ }
+ }
+};
diff --git a/packages/benchmark/fixtures/restrict-plus-operands/test1.ts b/packages/benchmark/fixtures/restrict-plus-operands/test1.ts
new file mode 100644
index 000000000000..aa88a44282b9
--- /dev/null
+++ b/packages/benchmark/fixtures/restrict-plus-operands/test1.ts
@@ -0,0 +1 @@
+const test = 'a' + 1
diff --git a/packages/benchmark/fixtures/restrict-plus-operands/test2.ts b/packages/benchmark/fixtures/restrict-plus-operands/test2.ts
new file mode 100644
index 000000000000..aa88a44282b9
--- /dev/null
+++ b/packages/benchmark/fixtures/restrict-plus-operands/test2.ts
@@ -0,0 +1 @@
+const test = 'a' + 1
diff --git a/packages/benchmark/fixtures/restrict-plus-operands/test3.ts b/packages/benchmark/fixtures/restrict-plus-operands/test3.ts
new file mode 100644
index 000000000000..aa88a44282b9
--- /dev/null
+++ b/packages/benchmark/fixtures/restrict-plus-operands/test3.ts
@@ -0,0 +1 @@
+const test = 'a' + 1
diff --git a/packages/benchmark/fixtures/restrict-plus-operands/tsconfig.json b/packages/benchmark/fixtures/restrict-plus-operands/tsconfig.json
new file mode 100644
index 000000000000..3792da469e0e
--- /dev/null
+++ b/packages/benchmark/fixtures/restrict-plus-operands/tsconfig.json
@@ -0,0 +1,8 @@
+{
+ "compilerOptions": {
+ "declaration": true
+ },
+ "include": [
+ "./*"
+ ]
+}
diff --git a/packages/benchmark/fixtures/restrict-plus-operands/tslint.json b/packages/benchmark/fixtures/restrict-plus-operands/tslint.json
new file mode 100644
index 000000000000..8389b1de47a8
--- /dev/null
+++ b/packages/benchmark/fixtures/restrict-plus-operands/tslint.json
@@ -0,0 +1,5 @@
+{
+ "rules": {
+ "restrict-plus-operands": true
+ }
+}
diff --git a/packages/benchmark/package.json b/packages/benchmark/package.json
new file mode 100644
index 000000000000..58f4d26fcdc5
--- /dev/null
+++ b/packages/benchmark/package.json
@@ -0,0 +1,22 @@
+{
+ "name": "@typescript-eslint/benchmark",
+ "version": "1.1.0",
+ "private": true,
+ "scripts": {
+ "benchmark:rules": "node --allow-natives-syntax benchmark.js",
+ "benchmark:parsers": "node --allow-natives-syntax parsers.js",
+ "benchmark:e2e": "node --allow-natives-syntax e2e.js",
+ "eslint": "eslint --ext .ts fixtures/restrict-plus-operands",
+ "tslint": "tslint -p fixtures/restrict-plus-operands/tsconfig.json \"fixtures/restrict-plus-operands/*.ts\""
+ },
+ "devDependencies": {
+ "@types/benchmark": "^1.0.31",
+ "@types/eslint": "^4.16.5",
+ "@typescript-eslint/eslint-plugin": "1.1.1",
+ "@typescript-eslint/parser": "1.1.1",
+ "@typescript-eslint/typescript-estree": "1.1.1",
+ "benchmark": "^2.1.4",
+ "eslint": "^5.12.1",
+ "tslint": "^5.12.1"
+ }
+}
diff --git a/packages/benchmark/parsers.js b/packages/benchmark/parsers.js
new file mode 100644
index 000000000000..9565c262531f
--- /dev/null
+++ b/packages/benchmark/parsers.js
@@ -0,0 +1,90 @@
+const Benchmark = require('benchmark');
+const fs = require('fs');
+const path = require('path');
+const tsEstree = require('@typescript-eslint/typescript-estree');
+const tsParser = require('@typescript-eslint/parser');
+
+function runTSESTree(directory, files) {
+ for (const file of files) {
+ const result = tsEstree.parse(
+ fs.readFileSync(path.join(__dirname, file), 'utf8'),
+ {
+ comment: true,
+ tokens: true
+ }
+ );
+ if (result.type !== 'Program') {
+ throw new Error('something went wrong');
+ }
+ }
+}
+
+function runTSParser(directory, files) {
+ for (const file of files) {
+ const result = tsParser.parse(
+ fs.readFileSync(path.join(__dirname, file), 'utf8'),
+ {
+ comment: true,
+ tokens: true
+ }
+ );
+ if (result.type !== 'Program') {
+ throw new Error('something went wrong');
+ }
+ }
+}
+
+function createBenchmark(name, directory, files) {
+ return new Promise((resolve, reject) => {
+ const suite = new Benchmark.Suite(name);
+ suite
+ .add('ts-estree', function() {
+ runTSESTree(directory, files);
+ })
+ .add('ts-parser', function tsParser() {
+ runTSParser(directory, files);
+ })
+ // add listeners
+ .on('cycle', function(event) {
+ console.log(String(event.target));
+ })
+ .on('error', function(e) {
+ reject(e);
+ })
+ .on('complete', function() {
+ console.log(
+ `Fastest is ${this.filter('fastest')
+ .map(i => i.name)
+ .join(', ')}`
+ );
+ resolve();
+ })
+ .run({
+ async: true,
+ minSamples: 100000,
+ initCount: 100000
+ });
+ });
+}
+
+async function runAllBenchmarks(scenarios) {
+ for (const scenario of scenarios) {
+ console.log(scenario.name);
+ await createBenchmark(scenario.name, scenario.directory, scenario.files);
+ }
+}
+
+runAllBenchmarks([
+ {
+ name: 'Complex File',
+ directory: 'fixtures/complex/',
+ files: ['fixtures/complex/test.ts']
+ },
+ {
+ name: 'Simple File',
+ directory: 'fixtures/restrict-plus-operands/',
+ files: ['fixtures/restrict-plus-operands/test1.ts']
+ }
+]).catch(e => {
+ console.log(e);
+});
diff --git a/packages/benchmark/tsconfig.json b/packages/benchmark/tsconfig.json
new file mode 100644
index 000000000000..38e6103e9c6e
--- /dev/null
+++ b/packages/benchmark/tsconfig.json
@@ -0,0 +1,7 @@
+{
+ "extends": "../../tsconfig.json",
+ "compilerOptions": {
+ "declaration": true
+ },
+ "include": ["src"]
+}
diff --git a/packages/benchmark/tslint-runner.js b/packages/benchmark/tslint-runner.js
new file mode 100644
index 000000000000..aff8f3c5fe0d
--- /dev/null
+++ b/packages/benchmark/tslint-runner.js
@@ -0,0 +1,31 @@
+const tslint = require('tslint');
+const path = require('path');
+const fs = require('fs');
+
+exports.runTSLint = function(directory, files, useServices) {
+ const program = useServices
+ ? tslint.Linter.createProgram(`${directory}tsconfig.json`)
+ : undefined;
+ const linter = new tslint.Linter(
+ {
+ fix: false,
+ formatter: 'json'
+ },
+ program
+ );
+ const tslintConfig = tslint.Configuration.loadConfigurationFromPath(
+ `./${directory}tslint.json`
+ );
+ for (const file of files) {
+ linter.lint(
+ file,
+ fs.readFileSync(path.join(__dirname, file), 'utf8'),
+ tslintConfig
+ );
+ }
+ const result = linter.getResult();
+ if (result.errorCount === 0) {
+ throw new Error('something went wrong');
+ }
+ return result.failures[0].failure;
+};
diff --git a/yarn.lock b/yarn.lock
index b6a6d614dfc0..c91501604006 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -803,6 +803,11 @@
resolved "https://registry.yarnpkg.com/@types/babel-code-frame/-/babel-code-frame-6.20.1.tgz#e79a40ea81435034df7b46b5e32e8ed638aea4dd"
integrity sha1-55pA6oFDUDTfe0a14y6O1jiupN0=
+"@types/benchmark@^1.0.31":
+ version "1.0.31"
+ resolved "https://registry.yarnpkg.com/@types/benchmark/-/benchmark-1.0.31.tgz#2dd3514e93396f362ba5551a7c9ff0da405c1d38"
+ integrity sha512-F6fVNOkGEkSdo/19yWYOwVKGvzbTeWkR/XQYBKtGBQ9oGRjBN9f/L4aJI4sDcVPJO58Y1CJZN8va9V2BhrZapA==
+
"@types/eslint-visitor-keys@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d"
@@ -1361,6 +1366,14 @@ bcrypt-pbkdf@^1.0.0:
dependencies:
tweetnacl "^0.14.3"
+benchmark@^2.1.4:
+ version "2.1.4"
+ resolved "https://registry.yarnpkg.com/benchmark/-/benchmark-2.1.4.tgz#09f3de31c916425d498cc2ee565a0ebf3c2a5629"
+ integrity sha1-CfPeMckWQl1JjMLuVloOvzwqVik=
+ dependencies:
+ lodash "^4.17.4"
+ platform "^1.3.3"
+
bin-links@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/bin-links/-/bin-links-1.1.2.tgz#fb74bd54bae6b7befc6c6221f25322ac830d9757"
@@ -5743,6 +5756,11 @@ pkg-dir@^3.0.0:
dependencies:
find-up "^3.0.0"
+platform@^1.3.3:
+ version "1.3.5"
+ resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.5.tgz#fb6958c696e07e2918d2eeda0f0bc9448d733444"
+ integrity sha512-TuvHS8AOIZNAlE77WUDiR4rySV/VMptyMfcfeoMgs4P8apaZM3JrnbzBiixKUv+XR6i+BXrQh8WAnjaSPFO65Q==
+
please-upgrade-node@^3.0.2, please-upgrade-node@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/please-upgrade-node/-/please-upgrade-node-3.1.1.tgz#ed320051dfcc5024fae696712c8288993595e8ac"
@@ -7000,7 +7018,7 @@ tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
integrity sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==
-tslint@^5.11.0:
+tslint@^5.11.0, tslint@^5.12.1:
version "5.12.1"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.12.1.tgz#8cec9d454cf8a1de9b0a26d7bdbad6de362e52c1"
integrity sha512-sfodBHOucFg6egff8d1BvuofoOQ/nOeYNfbp7LDlKBcLNrL3lmS5zoiDGyOMdT7YsEXAwWpTdAHwOGOc8eRZAw==
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy