Repository: jhipster/generator-jhipster (ts)

Issue:
Git commit fails in Windows after lint-staged upgrade to v9
<!--
- Please follow the issue template below for bug reports.
- If you have a support request rather than a bug, please use [Stack Overflow](http://stackoverflow.com/questions/tagged/jhipster) with the JHipster tag.
- For bug reports it is mandatory to run the command `jhipster info` in your project's root folder, and paste the result here.
- Tickets opened without any of these pieces of information will be **closed** without any explanation.
-->

##### **Overview of the issue**

<!-- Explain the bug, if an error is being thrown a stack trace helps -->

#10254 upgraded `lint-staged` version from 8.2.0 to 9.2.3.  

After that initial generated application is not committed to Git in Windows, the following error occurs:
  <details>
  <summary>Git commit error in Windows</summary>
  <pre>
husky > pre-commit (node v10.15.3)
‼  lint-staged generated an argument string of 21937 characters, and commands might not run correctly on your platform.
It is recommended to use functions as linters and split your command based on the number of staged files. For more info, please visit:
https://github.com/okonet/lint-staged#using-js-functions-to-customize-linter-commands
Stashing changes... [started]
Stashing changes... [skipped]
→ No partially staged files found...
Running tasks... [started]
Running tasks for {,src/**/}*.{md,json,ts,css,scss,yml} [started]
prettier --write [started]
prettier --write [failed]
→ 
Running tasks for {,src/**/}*.{md,json,ts,css,scss,yml} [failed]
→ 
Running tasks... [failed]



× prettier --write found some errors. Please fix them and try committing again.

The command line is too long.
husky > pre-commit hook failed (add --no-verify to bypass)


git did not exit cleanly (exit code 1) (1422 ms @ 30.08.2019 03:38:55)
  </pre>
  </details>

`lint-staged` has some breaking changes from version 9.0.0 (see https://github.com/okonet/lint-staged/releases), one of them is: "Very long arguments strings are no longer chunked on Windows. Function linters should be used instead to customise this behaviour.".

##### **Motivation for or Use Case**

<!-- Explain why this is a bug for you -->

Want to commit application to Git also in Windows.

##### **Reproduce the error**

<!-- For bug reports, an unambiguous set of steps to reproduce the error -->

Generate app in Windows with command `jhipster` and try to commit this to Git.

##### **Related issues**

<!-- Has a similar issue been reported before? Please search both closed & open issues -->

##### **Suggest a Fix**

<!-- If you can't fix the bug yourself, perhaps you can point to what might be
  causing the problem (line of code or commit) -->

Try to implement JS function as described in https://github.com/okonet/lint-staged#using-js-functions-to-customize-linter-commands

##### **JHipster Version(s)**

```
jhipster@0.0.1-SNAPSHOT C:\projects\teest\jhipster-git-commit2
`-- generator-jhipster@6.2.0  -> C:\projects\kaido-github\generator-jhipster

```


##### **JHipster configuration, a `.yo-rc.json` file generated in the root folder**


<details>
<summary>.yo-rc.json file</summary>
<pre>
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "com.mycompany.myapp",
      "nativeLanguage": "et"
    },
    "jhipsterVersion": "6.2.0",
    "applicationType": "monolith",
    "baseName": "jhipster",
    "packageName": "com.mycompany.myapp",
    "packageFolder": "com/mycompany/myapp",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "cacheProvider": "ehcache",
    "enableHibernateCache": true,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "prodDatabaseType": "mysql",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "gradle",
    "enableSwaggerCodegen": false,
    "jwtSecretKey": "bXktc2VjcmV0LXRva2VuLXRvLWNoYW5nZS1pbi1wcm9kdWN0aW9uLWFuZC10by1rZWVwLWluLWEtc2VjdXJlLXBsYWNl",
    "useSass": true,
    "clientPackageManager": "npm",
    "clientFramework": "angularX",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "otherModules": [],
    "enableTranslation": true,
    "nativeLanguage": "et",
    "languages": ["et", "en", "ru"],
    "blueprints": []
  }
}

</pre>
</details>


##### **JDL for the Entity configuration(s) `entityName.json` files generated in the `.jhipster` directory**

<details>
<summary>JDL entity definitions</summary>

<pre>

</pre>
</details>


##### **Environment and Tools**

java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)

git version 2.21.0.windows.1

node: v10.15.3

npm: 6.9.0

yeoman: 2.0.6

yarn: 1.15.2

Docker version 19.03.1, build 74b1e89

docker-compose version 1.24.1, build 4667896b

##### **Browsers and Operating System**

<!-- What OS are you on? is this a problem with all browsers or only IE8? -->

Windows 10

-   [x] Checking this box is mandatory (this is just to show you read everything)

<!-- Love JHipster? Please consider supporting our collective:
👉  https://opencollective.com/generator-jhipster/donate -->


Pull request:
Revert to old lint-staged version to fix issue on windows
- Closes #10312  
- Revert to old `lint-staged` dependency version that works on windows and doesn't degrade initial commit performance.
- Move lint-stage configurations to separate file, so, that future upgrade can be easy.
- Upgrade husky, lint-staged and prettier dependencies on react codebase to keep them in sync with angular.
---
-   Please make sure the below checklist is followed for Pull Requests.

-   [ ] [Travis tests](https://travis-ci.org/jhipster/generator-jhipster/pull_requests) are green
-   [ ] Tests are added where necessary
-   [ ] Documentation is added/updated where necessary
-   [ ] Coding Rules & Commit Guidelines as per our [CONTRIBUTING.md document](https://github.com/jhipster/generator-jhipster/blob/master/CONTRIBUTING.md) are followed

<!--
Please also reference the issue number in a commit message to [automatically close the related Github issue](https://help.github.com/articles/closing-issues-via-commit-messages/)

Note: It is also possible to add `[skip ci]` to your commit message to skip Travis tests
-->


Patch:
diff --git a/generators/client/files-angular.js b/generators/client/files-angular.js
index 51f240c245..0b94b49e8d 100644
--- a/generators/client/files-angular.js
+++ b/generators/client/files-angular.js
@@ -50,7 +50,7 @@ const files = {
         },
         {
             condition: generator => !generator.skipCommitHook,
-            templates: ['.huskyrc']
+            templates: ['.huskyrc', '.lintstagedrc.js']
         }
     ],
     sass: [
diff --git a/generators/client/files-react.js b/generators/client/files-react.js
index ac42dbb70b..23fcb8fafd 100644
--- a/generators/client/files-react.js
+++ b/generators/client/files-react.js
@@ -51,7 +51,7 @@ const files = {
         },
         {
             condition: generator => !generator.skipCommitHook,
-            templates: ['.huskyrc']
+            templates: ['.huskyrc', '.lintstagedrc.js']
         }
     ],
     sass: [
diff --git a/generators/client/templates/angular/.lintstagedrc.js.ejs b/generators/client/templates/angular/.lintstagedrc.js.ejs
new file mode 100644
index 0000000000..58dedb035c
--- /dev/null
+++ b/generators/client/templates/angular/.lintstagedrc.js.ejs
@@ -0,0 +1,3 @@
+module.exports = {
+  '{,src/**/}*.{md,json,ts,css,scss,yml}': ['prettier --write', 'git add']
+};
diff --git a/generators/client/templates/angular/package.json.ejs b/generators/client/templates/angular/package.json.ejs
index 8a4d9b924e..d0d9f1d3a0 100644
--- a/generators/client/templates/angular/package.json.ejs
+++ b/generators/client/templates/angular/package.json.ejs
@@ -109,7 +109,7 @@
     "jest-preset-angular": "7.1.1",
     "jest-sonar-reporter": "2.0.0",
     <%_ if (!skipCommitHook) { _%>
-    "lint-staged": "9.2.5",
+    "lint-staged": "8.2.1",
     <%_ } _%>
     <%_ if (enableTranslation) { _%>
     "merge-jsons-webpack-plugin": "1.0.19",
@@ -157,16 +157,8 @@
   },
   "engines": {
     "node": ">=8.9.0"<% if (clientPackageManager === 'yarn') { %>,
-    "yarn": ">=1.16.0"<% } %>
+    "yarn": ">=1.17.3"<% } %>
   },
-  <%_ if (!skipCommitHook) { _%>
-  "lint-staged": {
-    "{,src/**/}*.{md,json,ts,css,scss,yml}": [
-      "prettier --write",
-      "git add"
-    ]
-  },
-  <%_ } _%>
   "scripts": {
     "prettier:format": "prettier --write \"{,src/**/}*.{md,json,ts,css,scss,yml}\"",
     "lint": "eslint . --ext .js,.ts",
diff --git a/generators/client/templates/angular/src/main/webapp/app/app.module.ts.ejs b/generators/client/templates/angular/src/main/webapp/app/app.module.ts.ejs
index 087491ad64..2b6327326f 100644
--- a/generators/client/templates/angular/src/main/webapp/app/app.module.ts.ejs
+++ b/generators/client/templates/angular/src/main/webapp/app/app.module.ts.ejs
@@ -62,7 +62,7 @@ import { ErrorComponent } from './layouts/error/error.component';
             defaultI18nLang: '<%= nativeLanguage %>'
             <%_ } _%>
         }),
-        <%=angularXAppName%>SharedModule,
+        <%=angularXAppName%>SharedModule.forRoot(),
         <%=angularXAppName%>CoreModule,
         <%=angularXAppName%>HomeModule,
         <%_ if (!skipUserManagement) { _%>
diff --git a/generators/client/templates/angular/src/main/webapp/app/shared/shared-libs.module.ts.ejs b/generators/client/templates/angular/src/main/webapp/app/shared/shared-libs.module.ts.ejs
index 354d3bf2b6..d3407be8a5 100644
--- a/generators/client/templates/angular/src/main/webapp/app/shared/shared-libs.module.ts.ejs
+++ b/generators/client/templates/angular/src/main/webapp/app/shared/shared-libs.module.ts.ejs
@@ -43,4 +43,10 @@ import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
         ReactiveFormsModule
     ]
 })
-export class <%=angularXAppName%>SharedLibsModule {}
+export class <%=angularXAppName%>SharedLibsModule {
+    static forRoot() {
+        return {
+            ngModule: <%=angularXAppName%>SharedLibsModule
+        };
+    }
+}
diff --git a/generators/client/templates/angular/src/main/webapp/app/shared/shared.module.ts.ejs b/generators/client/templates/angular/src/main/webapp/app/shared/shared.module.ts.ejs
index 1391bce397..cae235655e 100644
--- a/generators/client/templates/angular/src/main/webapp/app/shared/shared.module.ts.ejs
+++ b/generators/client/templates/angular/src/main/webapp/app/shared/shared.module.ts.ejs
@@ -44,4 +44,10 @@ import { HasAnyAuthorityDirective } from './auth/has-any-authority.directive';
         HasAnyAuthorityDirective
     ]
 })
-export class <%=angularXAppName%>SharedModule {}
+export class <%=angularXAppName%>SharedModule {
+    static forRoot() {
+        return {
+            ngModule: <%=angularXAppName%>SharedModule
+        };
+    }
+}
diff --git a/generators/client/templates/react/.lintstagedrc.js.ejs b/generators/client/templates/react/.lintstagedrc.js.ejs
new file mode 100644
index 0000000000..58dedb035c
--- /dev/null
+++ b/generators/client/templates/react/.lintstagedrc.js.ejs
@@ -0,0 +1,3 @@
+module.exports = {
+  '{,src/**/}*.{md,json,ts,css,scss,yml}': ['prettier --write', 'git add']
+};
diff --git a/generators/client/templates/react/package.json.ejs b/generators/client/templates/react/package.json.ejs
index 4d0f571fb3..b1274c5d0e 100644
--- a/generators/client/templates/react/package.json.ejs
+++ b/generators/client/templates/react/package.json.ejs
@@ -113,7 +113,7 @@ limitations under the License.
     "generator-jhipster": "<%= packagejs.version %>",
     "html-webpack-plugin": "3.2.0",
     <%_ if (!skipCommitHook) { _%>
-    "husky": "1.3.1",
+    "husky": "3.0.4",
     <%_ } _%>
     "identity-obj-proxy": "3.0.0",
     "jest": "24.5.0",
@@ -121,7 +121,7 @@ limitations under the License.
     "jest-sonar-reporter": "2.0.0",
     "json-loader": "0.5.7",
     <%_ if (!skipCommitHook) { _%>
-    "lint-staged": "8.1.5",
+    "lint-staged": "8.2.1",
     <%_ } _%>
     <%_ if (enableTranslation) { _%>
     "merge-jsons-webpack-plugin": "1.0.18",
@@ -133,7 +133,7 @@ limitations under the License.
     "moment-locales-webpack-plugin": "1.0.7",
     "optimize-css-assets-webpack-plugin": "5.0.1",
     "postcss-loader": "3.0.0",
-    "prettier": "1.16.4",
+    "prettier": "1.18.2",
     <%_ if (protractorTests) { _%>
     "protractor": "5.4.2",
     <%_ } _%>
@@ -179,16 +179,8 @@ limitations under the License.
 <%_ } _%>
   "engines": {
     "node": ">=8.9.0"<% if (clientPackageManager === 'yarn') { %>,
-    "yarn": ">=1.3.2"<% } %>
+    "yarn": ">=1.17.3"<% } %>
   },
-  <%_ if (!skipCommitHook) { _%>
-  "lint-staged": {
-    "{,src/**/}*.{md,json,ts,tsx,css,scss,yml}": [
-      "prettier --write",
-      "git add"
-    ]
-  },
-  <%_ } _%>
   "scripts": {
     "prettier:format": "prettier --write \"{,src/**/}*.{md,json,ts,tsx,css,scss,yml}\"",
     "lint": "eslint . --ext .js,.ts,.jsx,.tsx",


Test patch:
diff --git a/generators/server/templates/src/test/java/package/service/UserServiceIT.java.ejs b/generators/server/templates/src/test/java/package/service/UserServiceIT.java.ejs
index cc7d5fed37..738efc6163 100644
--- a/generators/server/templates/src/test/java/package/service/UserServiceIT.java.ejs
+++ b/generators/server/templates/src/test/java/package/service/UserServiceIT.java.ejs
@@ -503,7 +503,7 @@ public class UserServiceIT <% if (databaseType === 'cassandra') { %>extends Abst
     <%_ if (databaseType === 'sql') { _%>
     @Transactional
     <%_ } _%>
-    public void testUserDetailsWithUSLocaleUnderscore() {
+    public void testUserDetailsWithUSLocale() {
         userDetails.put("locale", "en_US");
 
         OAuth2AuthenticationToken authentication = createMockOAuth2AuthenticationToken(userDetails);
@@ -516,7 +516,7 @@ public class UserServiceIT <% if (databaseType === 'cassandra') { %>extends Abst
     <%_ if (databaseType === 'sql') { _%>
     @Transactional
     <%_ } _%>
-    public void testUserDetailsWithUSLocaleDash() {
+    public void testUserDetailsWithUSLocale2() {
         userDetails.put("locale", "en-US");
 
         OAuth2AuthenticationToken authentication = createMockOAuth2AuthenticationToken(userDetails);
diff --git a/test/utils/expected-files.js b/test/utils/expected-files.js
index 6422851b81..022cf58ba1 100644
--- a/test/utils/expected-files.js
+++ b/test/utils/expected-files.js
@@ -359,6 +359,7 @@ const expectedFiles = {
         '.eslintrc.json',
         '.eslintignore',
         '.huskyrc',
+        '.lintstagedrc.js',
         'package.json',
         'postcss.config.js',
         'proxy.conf.json',