eslint-plugin-smarthr 0.3.8 → 0.3.9

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.3.9](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.3.8...v0.3.9) (2023-09-04)
6
+
7
+
8
+ ### Features
9
+
10
+ * `new Date("YYYY/MM/DD")` のように日付文字列を直接設定している場合 `new Date(YYYY, MM - 1, DD)` に置き換えるfixerを追加 ([#76](https://github.com/kufu/eslint-plugin-smarthr/issues/76)) ([16a689a](https://github.com/kufu/eslint-plugin-smarthr/commit/16a689a6fe9ef240baaf66bcac08992328a64c4e))
11
+
5
12
  ### [0.3.8](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.3.7...v0.3.8) (2023-09-01)
6
13
 
7
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-smarthr",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "author": "SmartHR",
5
5
  "license": "MIT",
6
6
  "description": "A sharable ESLint plugin for SmartHR",
@@ -5,10 +5,31 @@ const MESSAGE_PARSE = `Date.parse は実行環境によって結果が異なる
5
5
  - 'new Date(2022, 12 - 1, 31).getTime()' のように数値を個別に指定する
6
6
  - dayjsなど、日付系ライブラリを利用する (例: 'dayjs(arg).valueOf()')`
7
7
 
8
+ const SEPARATOR = '(\/|-)'
9
+ const DATE_REGEX = new RegExp(`^([0-9]{4})${SEPARATOR}([0-9]{1,2})${SEPARATOR}([0-9]{1,2})`)
10
+
11
+ const fixAction = (fixer, node, replacedSuffix = '') => {
12
+ const arg = node.arguments[0]
13
+
14
+ if (arg.type == 'Literal') {
15
+ const parsedArgs = arg.value.match(DATE_REGEX)
16
+
17
+ if (parsedArgs) {
18
+ return fixer.replaceText(
19
+ node,
20
+ `new Date(${parsedArgs[1] * 1}, ${parsedArgs[3] * 1} - 1, ${parsedArgs[5] * 1})${replacedSuffix}`
21
+ )
22
+ }
23
+ }
24
+ }
25
+
26
+ const SCHEMA = []
27
+
8
28
  module.exports = {
9
29
  meta: {
10
30
  type: 'problem',
11
- schema: [],
31
+ fixable: 'code',
32
+ schema: SCHEMA,
12
33
  },
13
34
  create(context) {
14
35
  return {
@@ -20,6 +41,7 @@ module.exports = {
20
41
  context.report({
21
42
  node,
22
43
  message: MESSAGE_NEW_DATE,
44
+ fix: (fixer) => fixAction(fixer, node),
23
45
  });
24
46
  }
25
47
  },
@@ -31,10 +53,11 @@ module.exports = {
31
53
  context.report({
32
54
  node,
33
55
  message: MESSAGE_PARSE,
56
+ fix: (fixer) => fixAction(fixer, node, '.getTime()'),
34
57
  });
35
58
  }
36
59
  },
37
60
  }
38
61
  },
39
62
  }
40
- module.exports.schema = []
63
+ module.exports.schema = SCHEMA