Skip to content
Permalink
Browse files

[JS] Introduce Typescript setup for libjoynr-js

* Use eslint to lint typescript files
** separate rules for .ts and .js and tests
* Use prettier eslint plugin to control formatting trough eslint
* Add jest dev-dependency to run tests
* Add typescript compile step to build step
  • Loading branch information...
Max van gen Hassend authored and donsciarra committed Apr 30, 2019
1 parent 22a3862 commit 5a2e0728565e7fc6aced366096c71c78a6ad29b7
@@ -22,13 +22,23 @@ module.exports = {
node: true,
commonjs: true,
jasmine: true,
jest: true,
browser: true
},
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 2017
ecmaVersion: 2018,
sourceType: "module"
},
extends: ["plugin:promise/recommended", "eslint:recommended"],
plugins: ["promise"],
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"prettier/@typescript-eslint",
"plugin:promise/recommended",
"plugin:prettier/recommended",
"eslint:recommended"
],
plugins: ["promise", "jest"],
rules: {
indent: "off",
quotes: "off",
@@ -87,6 +97,67 @@ module.exports = {
"promise/no-return-in-finally": "off",
"promise/valid-params": "off"
},
overrides: [
{
files: ["*.js"],
rules: {
"@typescript-eslint/adjacent-overload-signatures": "off",
"@typescript-eslint/array-type": "off",
"@typescript-eslint/ban-types": "off",
camelcase: "off",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/class-name-casing": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
indent: "off",
"@typescript-eslint/indent": "off",
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/member-delimiter-style": "off",
"@typescript-eslint/no-angle-bracket-type-assertion": "off",
"no-array-constructor": "off",
"@typescript-eslint/no-array-constructor": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-misused-new": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-object-literal-type-assertion": "off",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-triple-slash-reference": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/prefer-interface": "off",
"@typescript-eslint/prefer-namespace-keyword": "off",
"@typescript-eslint/type-annotation-spacing": "off",
// jest rules
"jest/no-alias-methods": "off",
"jest/no-disabled-tests": "off",
"jest/no-focused-tests": "off",
"jest/no-identical-title": "off",
"jest/no-jest-import": "off",
"jest/no-jasmine-globals": "off",
"jest/no-test-prefixes": "off",
"jest/valid-describe": "off",
"jest/valid-expect": "off",
"jest/valid-expect-in-promise": "off"
}
},
{
files: ["*.ts"],
rules: {
"no-useless-constructor": "off",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-explicit-any": "off"
}
},
{
files: ["*Test.ts"],
rules: { "@typescript-eslint/explicit-function-return-type": "off" }
}
],
globals: { define: false },
root: true
};
@@ -1,4 +1,4 @@
{
module.exports = {
"tabWidth": 4,
"printWidth": 120,
"useTabs": false,
@@ -9,4 +9,4 @@
"jsxBracketSameLine": false,
"requirePragma": false,
"insertPragma": false
}
};
@@ -0,0 +1,32 @@
module.exports = {
transform: {
"\\.ts$": "ts-jest"
},
testEnvironment: "node",
testRegex: "src/test/.*Test\\.ts$",
moduleFileExtensions: ["ts", "js", "json", "node"],
reporters: [
"default",
[
"jest-junit",
{
output: "target/test-results/ts-junit.xml"
}
]
],
coverageThreshold: {
"src/**/*.ts": {
branches: 80,
functions: 80,
lines: 80,
statements: 80
}
},
coverageDirectory: ".build/coverage/ts",
collectCoverageFrom: ["src/**/*.ts", "!src/**/*.d.ts"],
coveragePathIgnorePatterns: [
"/src/main/js/generated",
"/node_modules"
],
coverageReporters: ["cobertura", "lcov"]
};
@@ -6,14 +6,25 @@
"homepage": "http://joynr.io",
"bugs": "https://github.com/bmwcarit/joynr/issues",
"devDependencies": {
"@types/jest": "24.0.11",
"@types/nanoid": "1.2.1",
"@types/node": "8.9.4",
"@types/ws": "6.0.1",
"@typescript-eslint/eslint-plugin": "1.7.0",
"@typescript-eslint/parser": "1.7.0",
"await-semaphore": "0.1.3",
"browserify": "16.1.0",
"eslint": "4.15.0",
"eslint-plugin-promise": "^3.5.0",
"eslint": "5.16.0",
"eslint-config-prettier": "4.2.0",
"eslint-plugin-jest": "^22.5.1",
"eslint-plugin-prettier": "3.0.1",
"eslint-plugin-promise": "3.8.0",
"exit-hook": "1.1.1",
"jasmine": "3.2.0",
"jasmine-core": "3.2.1",
"jasmine-reporters": "2.1.1",
"jest": "24.7.1",
"jest-junit": "6.3.0",
"joynr": "file:./src/main/js",
"jsdoc": "3.5.5",
"karma": "2.0.0",
@@ -28,10 +39,12 @@
"nyc": "11.7.1",
"prettier": "1.13.2",
"proxyquire": "2.1.0",
"ts-jest": "24.0.1",
"typescript": "3.4.3",
"watchify": "3.11.0"
},
"config": {
"glob": "src/{{main/js/global,main/js/joynr,test/js/!(integration)}/**/*.js,main/js/*.js,test/js/*.js}"
"glob": "src/{main/js/global,main/js/joynr,test/js/!(integration)}/{**/*.js,**/*.ts}"
},
"engines": {
"node": ">=8.0.0"
@@ -53,18 +66,20 @@
"sig": "cd scripts && node createBuildSignature && cd -",
"clean": "rm -rf node_modules package-lock.json src/test/resources/localStorageTestResults src/main/js/node_modules src/main/browserify/node_modules out",
"format:install": "npm i prettier@1.13.2 --no-save && npm run format",
"format": "node_modules/.bin/prettier --write --config scripts/prettier.config.json $npm_package_config_glob",
"lint": "node_modules/.bin/eslint $npm_package_config_glob",
"lint:less": "node_modules/.bin/eslint $npm_package_config_glob --color | less -R",
"format": "node_modules/.bin/prettier --write $npm_package_config_glob",
"lint": "node_modules/.bin/eslint $npm_package_config_glob --max-warnings 0",
"lint:fix": "node_modules/.bin/eslint $npm_package_config_glob --fix",
"karma": "node_modules/.bin/karma start src/test/karma/karma.integration.conf.js --single-run",
"test": "npm run test:unit && npm run test:sit && npm run karma",
"test": "npm run ts:test && npm run test:unit && npm run test:sit && npm run karma",
"test:unit": "cd src/test/resources && nyc node node-run-unit-tests.js && cd -",
"test:sit": "cd src/test/resources && node node-run-system-integration-tests.js && cd -",
"build:fast": "npm run build:skip && npm run test",
"build": "npm run clean && npm run build:fast",
"build:skip": "cd src/main/js && npm i && cd ../../.. && npm i && npm run sig && npm run format && npm run lint && npm run fixRequire",
"fixRequire": "echo 'module.exports = require(\"..\");' > src/main/js/node_modules/joynr.js"
"build:skip": "cd src/main/js && npm i && cd ../../.. && npm i && npm run sig && npm run lint && npm run ts:compile && npm run fixRequire",
"fixRequire": "echo 'module.exports = require(\"..\");' > src/main/js/node_modules/joynr.js",
"ts:compile": "tsc --noImplicitUseStrict",
"ts:check": "tsc --noEmit",
"ts:test": "jest --config jest.config.js --silent"
},
"repository": {
"type": "git",
@@ -376,7 +376,8 @@
<exclude>src/main/js/lib/JsonParser.js</exclude>
<exclude>src/test/resources/node/shutdown/package.json</exclude>
<exclude>src/test/resources/spec/support/jasmine.json</exclude>
<exclude>scripts/prettier.config.json</exclude>
<exclude>tsconfig.json</exclude>
<exclude>jest.config.js</exclude>
</excludes>
</configuration>
</plugin>
@@ -18,4 +18,5 @@
* limitations under the License.
* #L%
*/
// prettier-ignore
module.exports = "buildSignature";
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"moduleResolution": "node",
"module": "commonjs",
"target": "es2017",
"esModuleInterop": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictNullChecks": true,
"noImplicitThis": true,
"noImplicitAny": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"typeRoots": [
"node_modules/@types",
"typings"
]
},
"include": [
"src/**/*"
]
}

0 comments on commit 5a2e072

Please sign in to comment.
You can’t perform that action at this time.