Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

generate default eslint config from vue cli #601

Closed

Conversation

atomfrede
Copy link
Member

@atomfrede atomfrede commented May 2, 2020

With this PR the ap generates a default eslint config for vue + typescript as the vue-cli would create. As of our policy 1, I think thats fine. The huge work ahead to adhere to or define exceptions from the rules.

TODOs:

  • Cleanup: Remove tslint config

We have with a default app

40 errors and 158 warnings found.

Which seems okay to me. Most warnings (as it seems) are from tests with not used variables.

❓ Can we delete/cleanup old files in a blueprint? So can we overwrite the cleanup.js in a blueprint?

Closes #597
Updates #600

@pascalgrimaud
Copy link
Member

Can we delete/cleanup old files in a blueprint? So can we overwrite the cleanup.js in a blueprint?

Do you think it's possible @mshima ?

@atomfrede atomfrede force-pushed the 597-migrate-from-tslint-to-eslint branch from 09fbedc to 6d526b7 Compare June 9, 2020 04:52
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'@typescript-eslint/no-explicit-any': 'off',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just temporary until we have cleaned up the templates

entity[field] = null;
}
if (entity.hasOwnProperty(fieldContentType)) {
if (Object.prototype.hasOwnProperty.call(entity, fieldContentType)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are errors from es lint, which are now fixed/

@@ -3,9 +3,11 @@
<span v-if="i18nEnabled"
v-text="$t('global.item-count', {first, second, total })">Showing {{first}} - {{second}} of {{total}} items.</span>
<span v-if="!i18nEnabled">
<!-- eslint-disable vue/no-parsing-error -->
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule is disabled as I am pretty sure it is a false positive here.

@atomfrede atomfrede requested a review from pascalgrimaud June 9, 2020 04:59
@atomfrede
Copy link
Member Author

@pascalgrimaud I have ignored all warnings for now (a lot of unused vars, missing type declarations etc). If you like you can give this a try. The config is aligned with the default one from vue-cli, so Policy 1 is totally in place :)

@pascalgrimaud
Copy link
Member

pascalgrimaud commented Jun 9, 2020

Good job, I'll have a look @atomfrede
For your information, the builds failed because of:

Error: Copying template vue/package.json.ejs failed. [ReferenceError: /home/runner/work/jhipster-vuejs/jhipster-vuejs/generators/client/templates/vue/package.json.ejs:163
    161|     "lint": "vue-cli-service lint",
    162|     "lint:fix": "<%= clientPackageManager %> run lint <%= optionsForwarder %>--fix",
 >> 163|     "cleanup": "rimraf <%= DIST_DIR %> <%= AOT_DIR %>",
    164|     "clean-www": "rimraf <%= DIST_DIR %>app/{src,<%= BUILD_DIR %>}",
    165|     "start": "<%= clientPackageManager %> run webpack:dev",
    166|     "start-tls": "<%= clientPackageManager %> run webpack:dev <%= optionsForwarder %>--env.tls",

AOT_DIR is not defined]
    at module.exports.error (/home/runner/generator-jhipster/generators/generator-base.js:1590:15)
    at /home/runner/generator-jhipster/generators/utils.js:256:23
    at tryHandleCache (/home/runner/generator-jhipster/node_modules/ejs/lib/ejs.js:275:14)
    at Object.exports.renderFile (/home/runner/generator-jhipster/node_modules/ejs/lib/ejs.js:478:10)
    at Object.renderContent (/home/runner/generator-jhipster/generators/utils.js:252:9)

Can you fix it ?

@atomfrede
Copy link
Member Author

Good job, I'll have a look @atomfrede
For your information, the builds failed because of:

Error: Copying template vue/package.json.ejs failed. [ReferenceError: /home/runner/work/jhipster-vuejs/jhipster-vuejs/generators/client/templates/vue/package.json.ejs:163
    161|     "lint": "vue-cli-service lint",
    162|     "lint:fix": "<%= clientPackageManager %> run lint <%= optionsForwarder %>--fix",
 >> 163|     "cleanup": "rimraf <%= DIST_DIR %> <%= AOT_DIR %>",
    164|     "clean-www": "rimraf <%= DIST_DIR %>app/{src,<%= BUILD_DIR %>}",
    165|     "start": "<%= clientPackageManager %> run webpack:dev",
    166|     "start-tls": "<%= clientPackageManager %> run webpack:dev <%= optionsForwarder %>--env.tls",

AOT_DIR is not defined]
    at module.exports.error (/home/runner/generator-jhipster/generators/generator-base.js:1590:15)
    at /home/runner/generator-jhipster/generators/utils.js:256:23
    at tryHandleCache (/home/runner/generator-jhipster/node_modules/ejs/lib/ejs.js:275:14)
    at Object.exports.renderFile (/home/runner/generator-jhipster/node_modules/ejs/lib/ejs.js:478:10)
    at Object.renderContent (/home/runner/generator-jhipster/generators/utils.js:252:9)

Can you fix it ?

I have seen it, but thats strange as I did not change something there. But I will have a look.

@kaidohallik
Copy link
Contributor

I made #628 for fix. This error is caused by jhipster/generator-jhipster#11907

@atomfrede
Copy link
Member Author

Thanks @kaidohallik

@atomfrede atomfrede linked an issue Jun 9, 2020 that may be closed by this pull request
@mshima
Copy link
Member

mshima commented Jun 9, 2020

Do you think it's possible @mshima ?

Saw just now.

Can we delete/cleanup old files in a blueprint? So can we overwrite the cleanup.js in a blueprint?

Is there specific behavior to override cleanup.js?

I suggest to add a task to writing priority:

cleanup() {
  this.deleteDestination('tslint.json');
}

The behavior is a bit different than the generator-base-private's removeFile:

  • deleteDestination (yeoman-generator) - queues the file to be removed at the conflicts priority.
  • removeFile (generator-base-private) - removes the file from filesystem with shelljs.

isJhipsterVersionLessThan can be used in conjunction of this.jhipsterOldVersion = this.config.get('jhipsterVersion'); but depends on what stage the following was called.

I would suggest each blueprint to write it's own generatedWith version (at the constructor):

// Assume 6.8.0 if value is not set.
this.oldBlueprintVersion = this.blueprintConfig.get('generatedWith') || '6.8.0';
this.blueprintConfig.set('generatedWith', packageJson.version);
if (semver.lt(this.oldBlueprintVersion, desiredVersion)) {
  ... deleteFile;
}

@atomfrede atomfrede force-pushed the 597-migrate-from-tslint-to-eslint branch from d3f86f6 to 7cce6d0 Compare June 9, 2020 17:51
@atomfrede
Copy link
Member Author

atomfrede commented Jun 9, 2020

Thanks @mshima for the detailed explanation. I think we can go with deleting the not needed tslint config.

@pascalgrimaud rebased against master which removes aot_dir. And updated es lint config of the blueprint code itself.

@atomfrede atomfrede force-pushed the 597-migrate-from-tslint-to-eslint branch from eba8836 to 6ce0d0a Compare June 9, 2020 20:57
@pascalgrimaud
Copy link
Member

Just tried it, and here 2 comments:

  • npm run lint -> there is an auto fix here, instead of displaying lint error, the behavior has changed here
  • all vue files uses 2 indents instead of 4, so our generated files will conflict a lot when we'll upgrade our application

@atomfrede
Copy link
Member Author

Both should be configurable. Will have a look.

@atomfrede
Copy link
Member Author

@pascalgrimaud both should be fixed now.

@pascalgrimaud
Copy link
Member

@atomfrede : is this PR still in draft ?

@atomfrede
Copy link
Member Author

The old tslint config file is not yet removed. Otherwise it's good to be merged. The now ignored rules can be fixed afterwards imho

@atomfrede
Copy link
Member Author

Regarding the cleanup we could

  • Do it here (e.g. look at the current config/package.json to determine the used blueprint version). And create a cleanup procedure like we have for the main generator
  • Keep the tslint.json config file for now (it is not generated anymore for new apps)
  • Just try to delete tslint.json

@pascalgrimaud pascalgrimaud marked this pull request as ready for review June 29, 2020 08:15
@pascalgrimaud
Copy link
Member

I'm reviewing this. Here some comments:

After the initial generation, when running npm run lint, I have:

1789 warnings found.
1789 warnings potentially fixable with the `--fix` option.

So, I launch: npm run lint:fix, and I still have:

5 errors and 1416 warnings found.
1413 warnings potentially fixable with the `--fix` option.

I think it's not nice to have so much warning.
So I completed with prettier:

diff --git a/.prettierrc b/.prettierrc
index f9b9911..8e8480b 100644
--- a/.prettierrc
+++ b/.prettierrc
@@ -16,3 +16,6 @@ overrides:
   - files: "*.java"
     options:
       tabWidth: 4
+  - files: "*.vue"
+    options:
+      tabWidth: 4
diff --git a/package.json b/package.json
index cdc807e..d3fdfab 100644
--- a/package.json
+++ b/package.json
@@ -102,7 +102,7 @@
     ]
   },
   "scripts": {
-    "prettier:format": "prettier --write \"{,src/**/,webpack/}*.{md,json,js,ts,tsx,css,scss}\"",
+    "prettier:format": "prettier --write \"{,src/**/,webpack/}*.{md,json,js,ts,tsx,css,scss,vue}\"",
     "lint": "vue-cli-service lint --no-fix",
     "lint:fix": "vue-cli-service lint",
     "cleanup": "rimraf target/classes/static/",

Then, I needed to fix some prettier error, and finally, the result is better:

16 warnings found.
16 warnings potentially fixable with the `--fix` option.

With only 16 warnings, I'm sure we can fix all of them to have 0 warning.

@atomfrede :

  • we should add prettier to help us here
  • we should fix the prettier error
  • we should fix the last warning
  • what do you think ?

@atomfrede
Copy link
Member Author

Sounds good. In my sample application I think I was already on 0 lint warnings/errors but I adapted it manually. Should we have an upgrade notice to manually have the old tslint config file deleted and come up with a general approach how to clean up old files?

@pascalgrimaud
Copy link
Member

We can simply add it the our release note.
No need to add more code in our blueprint to delete this file...

@pascalgrimaud
Copy link
Member

@atomfrede : do you want me to finish this PR, with my previous comments ?

@atomfrede
Copy link
Member Author

@pascalgrimaud If you have some spare time please go ahead. Otherwise I will pick it up on wednesday most likely.

@pascalgrimaud
Copy link
Member

So, I didn't manage to go further, as there is no similar method in this blueprint: https://github.com/jhipster/generator-jhipster/blob/master/generators/generator-base-private.js#L1601-L1610

@pascalgrimaud
Copy link
Member

Sorry for this PR @atomfrede but is it possible to report your commits into generator-jhipster ?
I tried to finish your PR before working on the merge, but I was stuck.

@atomfrede
Copy link
Member Author

Sure was already thinking if we finish it here or just in the main generator.

@pascalgrimaud
Copy link
Member

I prefer generator-jhipster directly, as I think I won't wait months before doing v7 release.
Remember we can do v7-beta release :-)

@pascalgrimaud
Copy link
Member

closed by jhipster/generator-jhipster#12972

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prettier / eslint: vue files Migrate from tslint to eslint
4 participants