diff --git a/.eslintrc.js b/.eslintrc.js index 7046abe..fc4df69 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -36,7 +36,7 @@ module.exports = { settings: { "import/resolver": { node: { - extensions: [".js", ".jsx", ".ts", ".tsx"] + extensions: [".ts"] } } } diff --git a/package-lock.json b/package-lock.json index 1c9829f..08564cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -274,12 +274,28 @@ "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==" }, + "@types/eslint": { + "version": "6.1.3", + "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-6.1.3.tgz", + "integrity": "sha512-llYf1QNZaDweXtA7uY6JczcwHmFwJL9TpK3E6sY0B18l6ulDT6VWNMAdEjYccFHiDfxLPxffd8QmSDV4QUUspA==", + "dev": true, + "requires": { + "@types/estree": "*", + "@types/json-schema": "*" + } + }, "@types/eslint-visitor-keys": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", "integrity": "sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==", "dev": true }, + "@types/estree": { + "version": "0.0.41", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.41.tgz", + "integrity": "sha512-rIAmXyJlqw4KEBO7+u9gxZZSQHaCNnIzYrnNmYVpgfJhxTqO0brCX0SYpqUTkVI5mwwUwzmtspLBGBKroMeynA==", + "dev": true + }, "@types/events": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz", diff --git a/package.json b/package.json index d70caee..4ec7766 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "@types/chai": "^4.2.7", "@types/chai-as-promised": "^7.1.2", "@types/chai-subset": "^1.3.3", + "@types/eslint": "^6.1.3", "@types/fs-extra": "^8.0.1", "@types/handlebars": "^4.1.0", "@types/inquirer": "^6.5.0", diff --git a/src/templates/entity.mst b/src/templates/entity.mst index 6e16182..ce84e6b 100644 --- a/src/templates/entity.mst +++ b/src/templates/entity.mst @@ -13,7 +13,7 @@ import { {{toEntityName .}} } from './{{toFileName .}}' { name: "{{name}}", referencedColumnName: "{{toPropertyName referencedColumnName}}" }, {{/inline}} {{#*inline "Relation"}} -@{{relationType}}(()=>{{toEntityName relatedTable}},{{toEntityName relatedTable}}=>{{toEntityName relatedTable}}.{{toPropertyName relatedField}}{{#if relationOptions}},{ {{json relationOptions}} }{{/if}}) +@{{relationType}}(()=>{{toEntityName relatedTable}},{{toEntityName relatedTable}}_=>{{toEntityName relatedTable}}_.{{toPropertyName relatedField}}{{#if relationOptions}},{ {{json relationOptions}} }{{/if}}) {{#if joinColumnOptions}}@JoinColumn([{{#joinColumnOptions}}{{> JoinColumnOptions}}{{/joinColumnOptions}}]){{/if}} {{#joinTableOptions}}@JoinTable({ name:"{{name}}", joinColumns:[{{#joinColumns}}{{> JoinColumnOptions}}{{/joinColumns}}],inverseJoinColumns:[{{#inverseJoinColumns}}{{> JoinColumnOptions}}{{/inverseJoinColumns}}],{{#database}}database:"{{.}}",{{/database}}{{#schema}}schema:"{{.}}"{{/schema}} }){{/joinTableOptions}} {{printPropertyVisibility}}{{toPropertyName fieldName}}{{strictMode}}:{{toRelation (toEntityName relatedTable) relationType}}; diff --git a/test/configs/.eslintrc.js b/test/configs/.eslintrc.js new file mode 100644 index 0000000..c2a28ca --- /dev/null +++ b/test/configs/.eslintrc.js @@ -0,0 +1,30 @@ +module.exports = { + env: { + node: true, + }, + extends: [ + "airbnb-base", + "plugin:@typescript-eslint/recommended", + "prettier", + "prettier/@typescript-eslint" + ], + parser: "@typescript-eslint/parser", + parserOptions: { + project: "test/configs/tsconfig.json" + }, + plugins: ["@typescript-eslint"], + rules: { // TODO: remove some rule overrides after disabling eslint on model customization tests(?) + "import/extensions": ["off"], + "import/prefer-default-export": ["off"], + "@typescript-eslint/no-explicit-any": ["off"], + "@typescript-eslint/camelcase": ["off"], + "@typescript-eslint/class-name-casing": ["off"] + }, + settings: { + "import/resolver": { + node: { + extensions: [".ts"] + } + } + } +}; diff --git a/test/configs/tsconfig.json b/test/configs/tsconfig.json new file mode 100644 index 0000000..8d56403 --- /dev/null +++ b/test/configs/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es2017", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "moduleResolution": "node", + "newLine": "LF", + "typeRoots": [ + "../../node_modules/@types" + ], + "resolveJsonModule": true, + }, + "include": [ + "../../output" + ] +} diff --git a/test/integration/runTestsFromPath.test.ts b/test/integration/runTestsFromPath.test.ts index ec5eb24..10981de 100644 --- a/test/integration/runTestsFromPath.test.ts +++ b/test/integration/runTestsFromPath.test.ts @@ -6,6 +6,7 @@ import * as path from "path"; import * as chaiSubset from "chai-subset"; import * as flatMap from "array.prototype.flatmap"; import yn from "yn"; +import { CLIEngine } from "eslint"; import EntityFileToJson from "../utils/EntityFileToJson"; import { createDriver, dataCollectionPhase } from "../../src/Engine"; import * as GTU from "../utils/GeneralTestUtils"; @@ -277,6 +278,15 @@ export function compileGeneratedModel(filesGenPath: string, drivers: string[]) { compiledWithoutErrors, "Errors detected while compiling generated model" ).to.equal(true); + + + const cli = new CLIEngine({ configFile: "test/configs/.eslintrc.js" }); + const lintReport = cli.executeOnFiles(currentDirectoryFiles) + lintReport.results.forEach(result => result.messages.forEach(message => { + console.error(`${result.filePath}:${message.line} - ${message.message}`) + })) + expect(lintReport.errorCount).to.equal(0) + expect(lintReport.warningCount).to.equal(0) } async function prepareTestRuns( diff --git a/tsconfig.json b/tsconfig.json index 93cff05..3c6e9eb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,29 +1,30 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es2017", - "noImplicitAny": false, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "sourceMap": true, - "declaration": false, - "noFallthroughCasesInSwitch": true, - "noImplicitReturns": true, - "stripInternal": true, - "strictNullChecks": true, - "moduleResolution": "node", - "newLine": "LF", - "outDir": "dist", - "lib": [ - "es2019","es2019.array" - ], - "typeRoots": [ - "./node_modules/@types" - ], - "resolveJsonModule": true, - }, - "include": [ - "src", - "test" - ] + "compilerOptions": { + "module": "commonjs", + "target": "es2017", + "noImplicitAny": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "sourceMap": true, + "declaration": false, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "stripInternal": true, + "strictNullChecks": true, + "moduleResolution": "node", + "newLine": "LF", + "outDir": "dist", + "lib": [ + "es2019", + "es2019.array" + ], + "typeRoots": [ + "./node_modules/@types" + ], + "resolveJsonModule": true, + }, + "include": [ + "src", + "test", + ] }