react-intl-lint 1.0.4 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/LICENSE.md +21 -21
  2. package/README.md +299 -229
  3. package/dist/bin.d.ts +2 -2
  4. package/dist/bin.js +4 -4
  5. package/dist/package.json +104 -121
  6. package/dist/src/cli/bin.d.ts +2 -2
  7. package/dist/src/cli/bin.js +17 -6
  8. package/dist/src/cli/bin.js.map +1 -1
  9. package/dist/src/cli/cli.d.ts +17 -16
  10. package/dist/src/cli/cli.js +219 -173
  11. package/dist/src/cli/cli.js.map +1 -1
  12. package/dist/src/cli/dictionaries/CliOptions.d.ts +3 -3
  13. package/dist/src/cli/dictionaries/CliOptions.js +171 -157
  14. package/dist/src/cli/dictionaries/CliOptions.js.map +1 -1
  15. package/dist/src/cli/dictionaries/index.d.ts +1 -1
  16. package/dist/src/cli/dictionaries/index.js +17 -17
  17. package/dist/src/cli/enums/OptionsNames.d.ts +31 -29
  18. package/dist/src/cli/enums/OptionsNames.js +35 -35
  19. package/dist/src/cli/enums/OptionsNames.js.map +1 -1
  20. package/dist/src/cli/enums/OptionsPath.d.ts +6 -5
  21. package/dist/src/cli/enums/OptionsPath.js +9 -9
  22. package/dist/src/cli/enums/OptionsPath.js.map +1 -1
  23. package/dist/src/cli/enums/index.d.ts +2 -2
  24. package/dist/src/cli/enums/index.js +18 -18
  25. package/dist/src/cli/models/Option.d.ts +7 -7
  26. package/dist/src/cli/models/Option.js +35 -35
  27. package/dist/src/cli/models/Option.js.map +1 -1
  28. package/dist/src/cli/models/index.d.ts +1 -1
  29. package/dist/src/cli/models/index.js +17 -17
  30. package/dist/src/cli/utils/file.d.ts +3 -3
  31. package/dist/src/cli/utils/file.js +59 -50
  32. package/dist/src/cli/utils/file.js.map +1 -1
  33. package/dist/src/cli/utils/index.d.ts +1 -1
  34. package/dist/src/cli/utils/index.js +17 -17
  35. package/dist/src/core/index.d.ts +1 -7
  36. package/dist/src/core/index.js +17 -23
  37. package/dist/src/core/index.js.map +1 -1
  38. package/dist/src/react-intl/regex.d.ts +1 -0
  39. package/dist/src/react-intl/regex.js +8 -0
  40. package/dist/src/react-intl/regex.js.map +1 -0
  41. package/package.json +104 -121
  42. package/dist/src/core/client.d.ts +0 -16
  43. package/dist/src/core/client.js +0 -171
  44. package/dist/src/core/client.js.map +0 -1
  45. package/dist/src/core/config.d.ts +0 -3
  46. package/dist/src/core/config.js +0 -24
  47. package/dist/src/core/config.js.map +0 -1
  48. package/dist/src/core/enums/ErrorFlow.d.ts +0 -15
  49. package/dist/src/core/enums/ErrorFlow.js +0 -20
  50. package/dist/src/core/enums/ErrorFlow.js.map +0 -1
  51. package/dist/src/core/enums/ErrorTypes.d.ts +0 -6
  52. package/dist/src/core/enums/ErrorTypes.js +0 -11
  53. package/dist/src/core/enums/ErrorTypes.js.map +0 -1
  54. package/dist/src/core/enums/StatusCodes.d.ts +0 -6
  55. package/dist/src/core/enums/StatusCodes.js +0 -11
  56. package/dist/src/core/enums/StatusCodes.js.map +0 -1
  57. package/dist/src/core/enums/ToggleRule.d.ts +0 -5
  58. package/dist/src/core/enums/ToggleRule.js +0 -10
  59. package/dist/src/core/enums/ToggleRule.js.map +0 -1
  60. package/dist/src/core/enums/index.d.ts +0 -4
  61. package/dist/src/core/enums/index.js +0 -21
  62. package/dist/src/core/enums/index.js.map +0 -1
  63. package/dist/src/core/interface/IAppConfig.d.ts +0 -10
  64. package/dist/src/core/interface/IAppConfig.js +0 -3
  65. package/dist/src/core/interface/IAppConfig.js.map +0 -1
  66. package/dist/src/core/interface/ILogger.d.ts +0 -5
  67. package/dist/src/core/interface/ILogger.js +0 -3
  68. package/dist/src/core/interface/ILogger.js.map +0 -1
  69. package/dist/src/core/interface/IMisprint.d.ts +0 -6
  70. package/dist/src/core/interface/IMisprint.js +0 -3
  71. package/dist/src/core/interface/IMisprint.js.map +0 -1
  72. package/dist/src/core/interface/IRule.d.ts +0 -8
  73. package/dist/src/core/interface/IRule.js +0 -3
  74. package/dist/src/core/interface/IRule.js.map +0 -1
  75. package/dist/src/core/interface/IRulesConfig.d.ts +0 -14
  76. package/dist/src/core/interface/IRulesConfig.js +0 -3
  77. package/dist/src/core/interface/IRulesConfig.js.map +0 -1
  78. package/dist/src/core/interface/IValidationMessage.d.ts +0 -5
  79. package/dist/src/core/interface/IValidationMessage.js +0 -3
  80. package/dist/src/core/interface/IValidationMessage.js.map +0 -1
  81. package/dist/src/core/interface/index.d.ts +0 -6
  82. package/dist/src/core/interface/index.js +0 -23
  83. package/dist/src/core/interface/index.js.map +0 -1
  84. package/dist/src/core/models/KeyModel.d.ts +0 -8
  85. package/dist/src/core/models/KeyModel.js +0 -15
  86. package/dist/src/core/models/KeyModel.js.map +0 -1
  87. package/dist/src/core/models/KeyModelWithLanguages.d.ts +0 -18
  88. package/dist/src/core/models/KeyModelWithLanguages.js +0 -29
  89. package/dist/src/core/models/KeyModelWithLanguages.js.map +0 -1
  90. package/dist/src/core/models/LanguagesModel.d.ts +0 -7
  91. package/dist/src/core/models/LanguagesModel.js +0 -12
  92. package/dist/src/core/models/LanguagesModel.js.map +0 -1
  93. package/dist/src/core/models/MisprintModel.d.ts +0 -8
  94. package/dist/src/core/models/MisprintModel.js +0 -12
  95. package/dist/src/core/models/MisprintModel.js.map +0 -1
  96. package/dist/src/core/models/StylishLogger.d.ts +0 -11
  97. package/dist/src/core/models/StylishLogger.js +0 -37
  98. package/dist/src/core/models/StylishLogger.js.map +0 -1
  99. package/dist/src/core/models/error/ErrorModel.d.ts +0 -7
  100. package/dist/src/core/models/error/ErrorModel.js +0 -4
  101. package/dist/src/core/models/error/ErrorModel.js.map +0 -1
  102. package/dist/src/core/models/error/FatalErrorModel.d.ts +0 -7
  103. package/dist/src/core/models/error/FatalErrorModel.js +0 -16
  104. package/dist/src/core/models/error/FatalErrorModel.js.map +0 -1
  105. package/dist/src/core/models/error/index.d.ts +0 -2
  106. package/dist/src/core/models/error/index.js +0 -19
  107. package/dist/src/core/models/error/index.js.map +0 -1
  108. package/dist/src/core/models/files/FileLanguageModel.d.ts +0 -10
  109. package/dist/src/core/models/files/FileLanguageModel.js +0 -90
  110. package/dist/src/core/models/files/FileLanguageModel.js.map +0 -1
  111. package/dist/src/core/models/files/FileModel.d.ts +0 -12
  112. package/dist/src/core/models/files/FileModel.js +0 -44
  113. package/dist/src/core/models/files/FileModel.js.map +0 -1
  114. package/dist/src/core/models/files/FileViewModel.d.ts +0 -7
  115. package/dist/src/core/models/files/FileViewModel.js +0 -22
  116. package/dist/src/core/models/files/FileViewModel.js.map +0 -1
  117. package/dist/src/core/models/files/index.d.ts +0 -3
  118. package/dist/src/core/models/files/index.js +0 -20
  119. package/dist/src/core/models/files/index.js.map +0 -1
  120. package/dist/src/core/models/index.d.ts +0 -8
  121. package/dist/src/core/models/index.js +0 -25
  122. package/dist/src/core/models/index.js.map +0 -1
  123. package/dist/src/core/models/results/ResultCliModel.d.ts +0 -22
  124. package/dist/src/core/models/results/ResultCliModel.js +0 -84
  125. package/dist/src/core/models/results/ResultCliModel.js.map +0 -1
  126. package/dist/src/core/models/results/ResultErrorModel.d.ts +0 -13
  127. package/dist/src/core/models/results/ResultErrorModel.js +0 -43
  128. package/dist/src/core/models/results/ResultErrorModel.js.map +0 -1
  129. package/dist/src/core/models/results/ResultFileModel.d.ts +0 -11
  130. package/dist/src/core/models/results/ResultFileModel.js +0 -16
  131. package/dist/src/core/models/results/ResultFileModel.js.map +0 -1
  132. package/dist/src/core/models/results/ResultModel.d.ts +0 -15
  133. package/dist/src/core/models/results/ResultModel.js +0 -62
  134. package/dist/src/core/models/results/ResultModel.js.map +0 -1
  135. package/dist/src/core/models/results/index.d.ts +0 -4
  136. package/dist/src/core/models/results/index.js +0 -21
  137. package/dist/src/core/models/results/index.js.map +0 -1
  138. package/dist/src/core/rules/AbsentViewKeysRule.d.ts +0 -12
  139. package/dist/src/core/rules/AbsentViewKeysRule.js +0 -38
  140. package/dist/src/core/rules/AbsentViewKeysRule.js.map +0 -1
  141. package/dist/src/core/rules/EmptyKeysRule.d.ts +0 -10
  142. package/dist/src/core/rules/EmptyKeysRule.js +0 -25
  143. package/dist/src/core/rules/EmptyKeysRule.js.map +0 -1
  144. package/dist/src/core/rules/MisprintRule.d.ts +0 -12
  145. package/dist/src/core/rules/MisprintRule.js +0 -38
  146. package/dist/src/core/rules/MisprintRule.js.map +0 -1
  147. package/dist/src/core/rules/ZombiesRule.d.ts +0 -10
  148. package/dist/src/core/rules/ZombiesRule.js +0 -26
  149. package/dist/src/core/rules/ZombiesRule.js.map +0 -1
  150. package/dist/src/core/rules/index.d.ts +0 -4
  151. package/dist/src/core/rules/index.js +0 -21
  152. package/dist/src/core/rules/index.js.map +0 -1
  153. package/dist/src/core/utils/index.d.ts +0 -4
  154. package/dist/src/core/utils/index.js +0 -21
  155. package/dist/src/core/utils/index.js.map +0 -1
  156. package/dist/src/core/utils/keys.d.ts +0 -7
  157. package/dist/src/core/utils/keys.js +0 -40
  158. package/dist/src/core/utils/keys.js.map +0 -1
  159. package/dist/src/core/utils/logger.d.ts +0 -3
  160. package/dist/src/core/utils/logger.js +0 -13
  161. package/dist/src/core/utils/logger.js.map +0 -1
  162. package/dist/src/core/utils/path.d.ts +0 -5
  163. package/dist/src/core/utils/path.js +0 -56
  164. package/dist/src/core/utils/path.js.map +0 -1
  165. package/dist/src/core/utils/shared.d.ts +0 -2
  166. package/dist/src/core/utils/shared.js +0 -24
  167. package/dist/src/core/utils/shared.js.map +0 -1
package/LICENSE.md CHANGED
@@ -1,21 +1,21 @@
1
- # MIT License
2
-
3
- Copyright (c) 2018
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ # MIT License
2
+
3
+ Copyright (c) 2018
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,229 +1,299 @@
1
- # react-intl-lint
2
-
3
- > Simple tools for check react-intl keys in whole app which use regexp.
4
-
5
- [![semantic](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
6
- [![npm](https://img.shields.io/npm/v/react-intl-lint.svg)](https://www.npmjs.com/package/react-intl-lint)
7
- [![download npm](https://img.shields.io/npm/dm/react-intl-lint.svg)](https://www.npmjs.com/package/react-intl-lint)
8
-
9
- > for `react-i18next` use [`react-i18next-lint`](https://www.npmjs.com/package/react-i18next-lint)
10
- >
11
- > for `ngx-translate` use [`ngx-translate-lint`](https://www.npmjs.com/package/ngx-translate-lint)
12
-
13
- ## Table of Contents
14
-
15
- - [Background](#background)
16
- - [Installation](#installation)
17
- - [Usage](#usage)
18
- - [CLI](#cli)
19
- - [TypeScript](#TypeScript)
20
- - [Contribute](#contribute)
21
- - [Used By](#UsedBy)
22
- - [License](#license)
23
-
24
- ## Background
25
-
26
- There are a lot of translation `react-intl` keys in the whole app.
27
- This repository contains a proposal to check all translation keys in the whole app
28
- which should exist in all languages files.
29
-
30
- ## Installation
31
-
32
- ### NPM
33
-
34
- ```bash
35
- npm install react-intl-lint -g
36
- ```
37
-
38
- ### GitHub
39
-
40
- The source code are available for download
41
- at [GitHub Releases][github-release-url] and
42
- [GitHub pages][github-pages-url] as well.
43
-
44
- ## Usage
45
-
46
- ### CLI
47
-
48
- ```text
49
-
50
- Usage: react-intl-lint [options]
51
-
52
- Simple CLI tools for check `react-intl` keys in app
53
-
54
- Options:
55
- -p, --project [glob] (required)
56
- The path to project folder
57
- Possible Values: <relative path|absolute path>
58
- (default: "./src/**/*.{html,ts,js}")
59
- -l, --languages [glob] (required)
60
- The path to languages folder
61
- Possible Values: <relative path|absolute path>
62
- (default: "./src/assets/i18n/*.json")
63
- -kv, --keysOnViews [enum]
64
- Described how to handle the error of missing keys on view
65
- Possible Values: <disable|warning|error>
66
- (default: "error")
67
- -zk, --zombieKeys [enum]
68
- Described how to handle the error of zombies keys
69
- Possible Values: <disable|warning|error>
70
- (default: "warning")
71
- -ek, --emptyKeys [enum]
72
- Described how to handle empty value on translate keys
73
- Possible Values: <disable|warning|error>
74
- (default: "warning")
75
- -i, --ignore [glob]
76
- Ignore projects and languages files
77
- Possible Values: <relative path|absolute path>
78
- --maxWarning [glob]
79
- Max count of warnings in all files. If this value more that count of warnings, then an error is return
80
- Possible Values: <number>
81
- (default: "0")
82
- -mk, --misprintKeys [enum]
83
- Try to find matches with misprint keys on views and languages keys. CCan be longer process!!
84
- Possible Values: <disable|warning|error>
85
- (default: "disable")
86
- -ds, --deepSearch [enum]
87
- Add each translate key to global regexp end try to find them on project. Can be longer process!!
88
- Possible Values: <disable|enable>
89
- (default: "disable")
90
- -mc, --misprintCoefficient [number]
91
- Coefficient for misprint option can be from 0 to 1.0.
92
- (default: "0.9")
93
- -c, --config [path]
94
- Path to the config file.
95
-
96
-
97
- -V, --version output the version number
98
- -h, --help output usage information
99
-
100
-
101
- Examples:
102
-
103
- $ npx react-intl-lint -p ./src/app/**/*.{html,ts,js} -l ./src/assets/i18n/*.json
104
- $ react-intl-lint -p ./src/app/**/*.{html,ts,js} -l ./src/assets/i18n/*.json
105
- $ react-intl-lint -p ./src/app/**/*.{html,ts,js} -z disable -v error
106
- ```
107
-
108
- > NOTE: For `project` and `languages` options need to include file types like on the example.
109
-
110
-
111
- Default Config is:
112
- ```json
113
- {
114
- "rules": {
115
- "keysOnViews": "error",
116
- "zombieKeys": "warning",
117
- "misprintKeys": "disable",
118
- "deepSearch": "disable",
119
- "emptyKeys": "warning",
120
- "maxWarning": "0",
121
- "misprintCoefficient": "0.9",
122
- "ignoredKeys": [ "IGNORED.KEY.(.*)" ], // can be string or RegExp
123
- "ignoredMisprintKeys": [],
124
- "customRegExpToFindKeys": [ "(?<=marker\\(['\"])([A-Za-z0-9_\\-.]+)(?=['\"]\\))"], // to find: marker('TRSNLATE.KEY');
125
- },
126
- "project": "./src/app/**/*.{html,ts,js}",
127
- "languages": "./src/assets/i18n/*.json"
128
- }
129
- ```
130
-
131
- #### How to write Custom RegExp
132
-
133
- We have `(?<=marker\\(['\"])([A-Za-z0-9_\\-.]+)(?=['\"]\\))` RegExp witch contains of 3 parts:
134
-
135
- - Prefix - `(?<=marker\\(['\"])`
136
- - This construction tells that what we need matching before translate key
137
- - start with `(?<=` and end `)`.
138
- - `marker\\(['\"]` - tells that we try to find word `market` witch have on the second character `'`or `"`
139
- - To summarize, we are trying to find keys before each word to be `market` and commas `'` or `"`
140
-
141
- - Matching for key: `([A-Za-z0-9_\\-.]+)`
142
- - This construction tells that we find and save all words which contain alphabet, numbers, and `_` or `-`.
143
- - We recommend using this part of RegExp to find and save translated keys
144
- - But you can also use `(.*)` If it's enough for your project
145
- - Postfix - `(?=['\"]\\))` (the same as prefix, but need to be ended)
146
- - This construction tells that what we need matching after translate key
147
- - start with `(?=` and end `)`
148
- - `['\"]\\)` - tells that we try to find word comas `'` or `"` and ended with `)`
149
- - To summarize, we are trying to find keys ended each word to be commas `'` or `"` and `)`
150
-
151
- Example RegExp will find following keys
152
- - `marker('TRSNLATE.KEY')`
153
- - `marker("TRSNLATE.KEY-2")`
154
-
155
- #### Exit Codes
156
-
157
- The CLI process may exit with the following codes:
158
-
159
- - `0`: Linting succeeded without errors (warnings may have occurred)
160
- - `1`: Linting failed with one or more rule violations with severity error
161
- - `2`: An invalid command line argument or combination thereof was used
162
-
163
- ### TypeScript
164
-
165
- ```typescript
166
- import { ToggleRule, ReactintlLint, IRulesConfig, ResultCliModel, ErrorTypes, LanguagesModel } from 'react-intl-lint';
167
-
168
- const viewsPath: string = './src/app/**/*.{html,ts,js}';
169
- const languagesPath: string = './src/assets/i18n/*.json';
170
- const ignoredLanguagesPath: string = "./src/assets/i18n/ru.json, ./src/assets/i18n/ru-RU.json";
171
- const ruleConfig: IRulesConfig = {
172
- keysOnViews: ErrorTypes.error,
173
- zombieKeys: ErrorTypes.warning,
174
- misprintKeys: ErrorTypes.disable,
175
- deepSearch: ToggleRule.disable,
176
- emptyKeys: ErrorTypes.warning,
177
- maxWarning: 0,
178
- misprintCoefficient: 0.9,
179
- ignoredKeys: [ 'EXAMPLE.KEY', 'IGNORED.KEY.(.*)' ], // can be string or RegExp
180
- ignoredMisprintKeys: [],
181
- customRegExpToFindKeys: [ "(?<=marker\\(['\"])([A-Za-z0-9_\\-.]+)(?=['\"]\\))" ] // to find: marker('TRSNLATE.KEY');
182
- };
183
-
184
- const reactIntlLint = new ReactIntlLint(viewsPath, languagesPath, ignoredLanguagesPath, ruleConfig)
185
- const resultLint: ResultCliModel = reactIntlLint.lint(); // Run Lint
186
- const languages: LanguagesModel[] = reactIntlLint.getLanguages() // Get Languages with all keys and views
187
-
188
- ```
189
-
190
- #### NOTE!
191
- If you have error `Can't resolve 'fs' in ...`. Please add next setting to you project:
192
-
193
- - tsconfig.json
194
- ```json
195
- {
196
- "skipLibCheck": true
197
- }
198
- ```
199
-
200
- ## Contribute
201
-
202
- You may contribute in several ways like requesting new features,
203
- adding tests, fixing bugs, improving documentation or examples.
204
- Please check our [contributing guidelines][contributing].
205
-
206
- ## Used By
207
-
208
- Here can be your extensions
209
-
210
- ## License
211
-
212
- [MIT][license-url]
213
-
214
- [react-intl]: https://formatjs.io/docs/getting-started/installation/
215
- [semantic-shield]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
216
- [semantic-url]: https://github.com/semantic-release/semantic-release
217
- [npm-shield]: https://img.shields.io/npm/v/svoboda-rabstvo/react-intl-lint.svg
218
- [npm-url]: https://www.npmjs.com/package/react-intl-lint
219
- [npm]: https://www.npmjs.com
220
- [node-js]: https://nodejs.org
221
- [github-shield]: https://img.shields.io/github/release/svoboda-rabstvo/react-intl-lint.svg?label=github
222
- [github-url]: https://github.com/svoboda-rabstvo/react-intl-lint
223
- [github-release-url]: https://github.com/svoboda-rabstvo/react-intl-lint/releases
224
- [github-pages-url]: https://svoboda-rabstvo.github.io/react-intl-lint/
225
- [schema-url]: http://json-schema.org/
226
- [doc-url]: https://github.com/svoboda-rabstvo/react-intl-lint/blob/develop/doc
227
- [license-url]: https://github.com/svoboda-rabstvo/react-intl-lint/blob/develop/LICENSE.md
228
- [meta-url]: https://en.wikipedia.org/wiki/List_of_software_package_management_systems#Meta_package_managers
229
- [contributing]: https://github.com/svoboda-rabstvo/react-intl-lint/blob/develop/.github/CONTRIBUTING.md
1
+ # react-intl-lint
2
+
3
+ > Simple tools for check react-intl keys in whole app which use regexp.
4
+
5
+ [![semantic](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
6
+ [![npm](https://img.shields.io/npm/v/react-intl-lint.svg)](https://www.npmjs.com/package/react-intl-lint)
7
+ [![download npm](https://img.shields.io/npm/dm/react-intl-lint.svg)](https://www.npmjs.com/package/react-intl-lint)
8
+
9
+ > for `react-i18next` use [`react-i18next-lint`](https://www.npmjs.com/package/react-i18next-lint)
10
+ >
11
+ > for `ngx-translate` use [`ngx-translate-lint`](https://www.npmjs.com/package/ngx-translate-lint)
12
+
13
+
14
+ ## Table of Contents
15
+
16
+ - [Background](#background)
17
+ - [Installation](#installation)
18
+ - [Usage](#usage)
19
+ - [CLI](#cli)
20
+ - [TypeScript](#TypeScript)
21
+ - [Contribute](#contribute)
22
+ - [Used By](#UsedBy)
23
+ - [License](#license)
24
+
25
+ ## Background
26
+
27
+ There are a lot of translation `react-intl` keys in the whole app.
28
+ This repository contains a proposal to check all translation keys in the whole app
29
+ which should exist in all languages files.
30
+
31
+ ## Installation
32
+
33
+ ### NPM
34
+
35
+ ```bash
36
+ npm install react-intl-lint -g
37
+ ```
38
+
39
+ ### GitHub
40
+
41
+ The source code are available for download
42
+ at [GitHub Releases][github-release-url] and
43
+ [GitHub pages][github-pages-url] as well.
44
+
45
+ ## Usage
46
+
47
+ ### CLI
48
+
49
+ ```text
50
+
51
+ Usage: react-intl-lint [options]
52
+
53
+ Simple CLI tools for check `react-intl` keys in app
54
+
55
+ Options:
56
+ -p, --project [glob]
57
+ The path to project folder
58
+ Possible Values: <relative path|absolute path>
59
+
60
+ -l, --languages [glob]
61
+ The path to languages folder
62
+ Possible Values: <relative path|absolute path|URL>
63
+
64
+ --kv, --keysOnViews [enum]
65
+ Described how to handle the error of missing keys on view
66
+ Possible Values: <disable|warning|error>
67
+
68
+ --zk, --zombieKeys [enum]
69
+ Described how to handle the error of zombies keys. Zombie keys are keys that doesn't exist on any languages file but exist on project, or exist languages but doesn't exist on project
70
+ Possible Values: <disable|warning|error>
71
+
72
+ --ek, --emptyKeys [enum]
73
+ Described how to handle empty value on translate keys. Empty keys are keys that doesn't have any value on languages files
74
+ Possible Values: <disable|warning|error>
75
+
76
+ -i, --ignore [glob]
77
+ Ignore projects and languages files
78
+ Possible Values: <relative path|absolute path>
79
+
80
+ --maxWarning [glob]
81
+ Max count of warnings in all files. If this value more that count of warnings, then an error is return
82
+ Possible Values: <number>
83
+
84
+ --mk, --misprintKeys [enum]
85
+ Try to find matches with misprint keys on views and languages keys. Coefficient: 0.9. Can be longer process!!
86
+ Possible Values: <disable|warning|error>
87
+
88
+ --ds, --deepSearch [enum]
89
+ Add each translate key to global regexp end try to find them on project. Can be longer process!!
90
+ Possible Values: <disable|enable>
91
+
92
+ --mc, --misprintCoefficient [number]
93
+ Coefficient for misprint option can be from 0 to 1.0.
94
+
95
+
96
+ -c, --config [path]
97
+ Path to config via JSON or JS file
98
+ Possible Values: <relative path|absolute path>
99
+
100
+ --fz, --fixZombiesKeys [boolean]
101
+ Auto fix zombies keys on languages files
102
+
103
+
104
+ -v, --version Print current version of react-intl-lint
105
+ -h, --help display help for command
106
+
107
+
108
+ Examples:
109
+
110
+ $ npx react-intl-lint -p ./src/app/**/*.{html,ts,js} -l ./src/assets/i18n/*.json
111
+ $ react-intl-lint -p ./src/app/**/*.{html,ts,js} -l ./src/assets/i18n/*.json
112
+ $ react-intl-lint -p ./src/app/**/*.{html,ts,js} -z disable -v error
113
+ $ react-intl-lint -p ./src/app/**/*.{html,ts,js} -l https://8.8.8.8/locales/EN-eu.json
114
+ ```
115
+
116
+ > NOTE: For `project` and `languages` options need to include file types like on the example.
117
+
118
+ Default JSON Config is:
119
+ ```json
120
+ {
121
+ "rules": {
122
+ "keysOnViews": "error",
123
+ "zombieKeys": "warning",
124
+ "misprintKeys": "disable",
125
+ "deepSearch": "disable",
126
+ "emptyKeys": "warning",
127
+ "maxWarning": "0",
128
+ "misprintCoefficient": "0.9",
129
+ "ignoredKeys": [ "IGNORED.KEY.(.*)" ], // can be string or RegExp
130
+ "ignoredMisprintKeys": [],
131
+ "customRegExpToFindKeys": [ "(?<=marker\\(['\"])([A-Za-z0-9_\\-.]+)(?=['\"]\\))"], // to find: marker('TRSNLATE.KEY');
132
+ },
133
+ "fetch": {
134
+ "requestQuery": "",
135
+ "requestHeaders": {},
136
+ "responseQuery": ""
137
+ },
138
+ "fixZombiesKeys": false,
139
+ "project": "./src/app/**/*.{html,ts}",
140
+ "languages": "./src/assets/i18n/*.json"
141
+ }
142
+ ```
143
+
144
+ JS Config should have `default` export via object like config. See example:
145
+
146
+ Example JS config is:
147
+ ```javascript
148
+
149
+ const config = {
150
+ rules: {
151
+ keysOnViews: "error",
152
+ zombieKeys: "warning",
153
+ emptyKeys: "warning",
154
+ misprint: {
155
+ type: "warning",
156
+ coefficient: 0.9
157
+ },
158
+ ignoredKeys: [],
159
+ ignoredMisprintKeys: []
160
+ },
161
+ fetch: {
162
+ requestQuery: "",
163
+ requestHeaders: {},
164
+ responseQuery: "",
165
+ get: async () => {
166
+ const requestOne = fetch('https://8.8.8.8/locales/EN-eu.json');
167
+ const requestTwo = fetch('https://8.8.8.8/locales/EN-us.json');
168
+ const result = await Promise.all([requestOne, requestTwo]).then(async ([responseOne, responseTwo]) => {
169
+ return {
170
+ ...(await responseOne.json()),
171
+ ...(await responseTwo.json())
172
+ }
173
+ });
174
+ // NOTE: result should contains only translation keys. Example
175
+ // {
176
+ // "translation.key": "value"
177
+ // }
178
+ return result;
179
+ }
180
+ },
181
+ fixZombiesKeys: false,
182
+ project: "./src/app/**/*.{html,ts}",
183
+ languages: "./src/assets/i18n/*.json"
184
+ }
185
+
186
+ export default config;
187
+ ```
188
+
189
+ #### How to write Custom RegExp
190
+
191
+ We have `(?<=marker\\(['\"])([A-Za-z0-9_\\-.]+)(?=['\"]\\))` RegExp witch contains of 3 parts:
192
+
193
+ - Prefix - `(?<=marker\\(['\"])`
194
+ - This construction tells that what we need matching before translate key
195
+ - start with `(?<=` and end `)`.
196
+ - `marker\\(['\"]` - tells that we try to find word `market` witch have on the second character `'`or `"`
197
+ - To summarize, we are trying to find keys before each word to be `market` and commas `'` or `"`
198
+
199
+ - Matching for key: `([A-Za-z0-9_\\-.]+)`
200
+ - This construction tells that we find and save all words which contain alphabet, numbers, and `_` or `-`.
201
+ - We recommend using this part of RegExp to find and save translated keys
202
+ - But you can also use `(.*)` If it's enough for your project
203
+ - Postfix - `(?=['\"]\\))` (the same as prefix, but need to be ended)
204
+ - This construction tells that what we need matching after translate key
205
+ - start with `(?=` and end `)`
206
+ - `['\"]\\)` - tells that we try to find word comas `'` or `"` and ended with `)`
207
+ - To summarize, we are trying to find keys ended each word to be commas `'` or `"` and `)`
208
+
209
+ Example RegExp will find following keys
210
+ - `marker('TRSNLATE.KEY')`
211
+ - `marker("TRSNLATE.KEY-2")`
212
+
213
+ #### Exit Codes
214
+
215
+ The CLI process may exit with the following codes:
216
+
217
+ - `0`: Linting succeeded without errors (warnings may have occurred)
218
+ - `1`: Linting failed with one or more rule violations with severity error
219
+ - `2`: An invalid command line argument or combination thereof was used
220
+
221
+ ### TypeScript
222
+
223
+ ```typescript
224
+ import {
225
+ ToggleRule,
226
+ NgxTranslateLint,
227
+ IRulesConfig,
228
+ ResultCliModel,
229
+ ErrorTypes,
230
+ LanguagesModel,
231
+ IFetch,
232
+ ngxTranslateRegEx,
233
+ } from 'ngx-translate-lint';
234
+
235
+ const viewsPath: string = './src/app/**/*.{html,ts}';
236
+ const languagesPath: string = './src/assets/i18n/*.json';
237
+ const ignoredLanguagesPath: string = "./src/assets/i18n/ru.json, ./src/assets/i18n/ru-RU.json";
238
+ const ruleConfig: IRulesConfig = {
239
+ keysOnViews: ErrorTypes.error,
240
+ zombieKeys: ErrorTypes.warning,
241
+ misprintKeys: ErrorTypes.disable,
242
+ deepSearch: ToggleRule.disable,
243
+ emptyKeys: ErrorTypes.warning,
244
+ maxWarning: 0,
245
+ misprintCoefficient: 0.9,
246
+ fixZombiesKeys: false,
247
+ ignoredKeys: ['EXAMPLE.KEY', 'IGNORED.KEY.(.*)'], // can be string or RegExp
248
+ ignoredMisprintKeys: [],
249
+ customRegExpToFindKeys: ["(?<=marker\\(['\"])([A-Za-z0-9_\\-.]+)(?=['\"]\\))"] // to find: marker('TRSNLATE.KEY');
250
+ };
251
+ const fixZombiesKeys: boolean = false;
252
+ const fetchSettings: IFetch = {
253
+ requestQuery: "",
254
+ requestHeaders: {},
255
+ responseQuery: "",
256
+ get: () => {
257
+ // You fetch to get locales
258
+ }
259
+ };
260
+ const ngxTranslateRegEx: ngxTranslateRegEx = ngxTranslateRegEx; // Here can be your array of regexp to find keys
261
+ const ngxTranslateLint = new NgxTranslateLint(viewsPath, languagesPath, ignoredLanguagesPath, ruleConfig, fixZombiesKeys, fetchSettings, ngxTranslateRegEx)
262
+ const resultLint: ResultCliModel = ngxTranslateLint.lint(); // Run Lint
263
+ const languages: LanguagesModel[] = ngxTranslateLint.getLanguages() // Get Languages with all keys and views
264
+
265
+ ```
266
+
267
+ ## Contribute
268
+
269
+ You may contribute in several ways like requesting new features,
270
+ adding tests, fixing bugs, improving documentation or examples.
271
+ Please check our [contributing guidelines][contributing].
272
+
273
+ ## Used By
274
+
275
+ Here can be your extensions:
276
+
277
+ - [ngx-translate-editor](https://github.com/svoboda-rabstvo/ngx-translate-editor) - Simple GUI for CRUD translate keys of ngx-translate, which included ngx-translate-lint
278
+ - [121 Platform](https://github.com/global-121/121-platform) - 121 is an open source platform for Cash based Aid built with Digital Identity & Local/Global Financial service partners.
279
+
280
+ ## License
281
+
282
+ [MIT][license-url]
283
+
284
+ [react-intl]: https://formatjs.io/docs/getting-started/installation/
285
+ [semantic-shield]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
286
+ [semantic-url]: https://github.com/semantic-release/semantic-release
287
+ [npm-shield]: https://img.shields.io/npm/v/svoboda-rabstvo/react-intl-lint.svg
288
+ [npm-url]: https://www.npmjs.com/package/react-intl-lint
289
+ [npm]: https://www.npmjs.com
290
+ [node-js]: https://nodejs.org
291
+ [github-shield]: https://img.shields.io/github/release/svoboda-rabstvo/react-intl-lint.svg?label=github
292
+ [github-url]: https://github.com/svoboda-rabstvo/react-intl-lint
293
+ [github-release-url]: https://github.com/svoboda-rabstvo/react-intl-lint/releases
294
+ [github-pages-url]: https://svoboda-rabstvo.github.io/react-intl-lint/
295
+ [schema-url]: http://json-schema.org/
296
+ [doc-url]: https://github.com/svoboda-rabstvo/react-intl-lint/blob/develop/doc
297
+ [license-url]: https://github.com/svoboda-rabstvo/react-intl-lint/blob/develop/LICENSE.md
298
+ [meta-url]: https://en.wikipedia.org/wiki/List_of_software_package_management_systems#Meta_package_managers
299
+ [contributing]: https://github.com/svoboda-rabstvo/react-intl-lint/blob/develop/.github/CONTRIBUTING.md
package/dist/bin.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env node
2
- import './src/cli/bin';
1
+ #!/usr/bin/env node
2
+ import './src/cli/bin';
package/dist/bin.js CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- require("./src/cli/bin");
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ require("./src/cli/bin");
5
5
  //# sourceMappingURL=bin.js.map