eslint-plugin-lube 0.1.4 → 0.1.6

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/package.json CHANGED
@@ -23,5 +23,5 @@
23
23
  "test": "mocha"
24
24
  },
25
25
  "type": "commonjs",
26
- "version": "0.1.4"
26
+ "version": "0.1.6"
27
27
  }
@@ -9,8 +9,7 @@ module.exports = {
9
9
  },
10
10
  fixable: "code",
11
11
  messages: {
12
- not_match: "Identifier '{{name}}' does not match for svelte's naming conventions.",
13
- not_match_private: "PrivateIdentifier '#{{name}}' does not match for svelte's naming conventions."
12
+ not_match: "Identifier '{{name}}' does not match for svelte's naming conventions."
14
13
  },
15
14
  schema: [{
16
15
  properties: {
@@ -45,6 +44,8 @@ module.exports = {
45
44
  const reported_declarations = new Set()
46
45
  /** @type {Map<string, import("../private").ASTNode[]>} */
47
46
  const pending_usages = new Map()
47
+ /** @type {Set<import("../private").ASTNode>} */
48
+ const shortand_properties = new Set()
48
49
 
49
50
  /** @param {import("../private").ASTNode} node */
50
51
  function defer(node) {
@@ -71,7 +72,8 @@ module.exports = {
71
72
  if (fixable_name_regex.test(name)) {
72
73
  return fixer.replaceTextRange(
73
74
  node.range,
74
- node.name.replace(fix_regex, fix_callback)
75
+ (shortand_properties.has(node) ? node.name + ": " : "")
76
+ + node.name.replace(fix_regex, fix_callback)
75
77
  )
76
78
  }
77
79
  return null
@@ -265,7 +267,6 @@ module.exports = {
265
267
  /* MetaProperty */
266
268
  // class Object { camelCase() {} }
267
269
  if ("MethodDefinition" == type) {
268
- report(node)
269
270
  return
270
271
  }
271
272
  // new camelCase
@@ -280,18 +281,16 @@ module.exports = {
280
281
  // var value = { key: value }
281
282
  // var { key: value } = value
282
283
  if ("Property" == type) {
283
- if (parent.value == node && parent.key.name != parent.value.name) {
284
+ if (parent.value == node) {
285
+ if (parent.key.name == parent.value.name) {
286
+ shortand_properties.add(node)
287
+ }
284
288
  defer(node)
285
289
  }
286
290
  return
287
291
  }
288
- // class Object { key = value }
292
+ // class Object { camelCase = value }
289
293
  if ("PropertyDefinition" == type) {
290
- if (parent.key == node) {
291
- report(node)
292
- } else {
293
- defer(node)
294
- }
295
294
  return
296
295
  }
297
296
  // var [ ...camelCase ] = value
@@ -387,24 +386,6 @@ module.exports = {
387
386
  defer(node)
388
387
  return
389
388
  }
390
- },
391
- /** @param {import("../private").ASTNode} node */
392
- PrivateIdentifier(node) {
393
- const name = node.name
394
- if (allow_regex.test(name)) return
395
- const parent = node.parent
396
- const type = parent.type
397
- // class Object { #camelCase() {} }
398
- if ("MethodDefinition" == type) {
399
- report(node)
400
- return
401
- }
402
- // class Object { #camelCase = value }
403
- if ("PropertyDefinition" == type) {
404
- report(node)
405
- return
406
- }
407
- // TODO ?
408
389
  }
409
390
  }
410
391
  }
@@ -786,13 +786,19 @@ exports.module = (valid, invalid) => {
786
786
  },
787
787
  // MethodDefinition
788
788
  {
789
- code: "class Object { camelCase() {} }",
789
+ code: `
790
+ class ObjectB { camelCase() {} }
791
+ var camelCase
792
+ `,
790
793
  errors: [{
791
794
  ...error,
792
- line: 1,
793
- column: 16
795
+ line: 3,
796
+ column: 8
794
797
  }],
795
- output: "class Object { camel_case() {} }",
798
+ output: `
799
+ class ObjectB { camelCase() {} }
800
+ var camel_case
801
+ `,
796
802
  parserOptions: { ecmaVersion: "latest" }
797
803
  },
798
804
  // NewExpression
@@ -852,6 +858,11 @@ exports.module = (valid, invalid) => {
852
858
  ...error,
853
859
  line: 5,
854
860
  column: 23
861
+ },
862
+ {
863
+ ...error,
864
+ line: 6,
865
+ column: 18
855
866
  }
856
867
  ],
857
868
  options: [{ fixSameNames: true }],
@@ -860,46 +871,32 @@ exports.module = (valid, invalid) => {
860
871
  var value = { key: pending_a }
861
872
  var pending_a
862
873
  var value = { key: pending_a }
863
- var value = { pendingA }
874
+ var value = { pendingA: pending_a }
864
875
  `,
865
876
  parserOptions: { ecmaVersion: "latest" }
866
877
  },
867
878
  // PropertyDefinition
868
879
  {
869
880
  code: `
870
- class ObjectA { camelCase = deferA }
871
- class ObjectB { snake_case = pendingA }
872
- var pendingA
873
- class ObjectC { snake_case = pendingA }
881
+ class ObjectB { camelCase = camelCase2 }
882
+ var camelCase, camelCase2
874
883
  `,
875
884
  errors: [
876
- {
877
- ...error,
878
- line: 2,
879
- column: 20
880
- },
881
885
  {
882
886
  ...error,
883
887
  line: 3,
884
- column: 33
885
- },
886
- {
887
- ...error,
888
- line: 4,
889
888
  column: 8
890
889
  },
891
890
  {
892
891
  ...error,
893
- line: 5,
894
- column: 33
892
+ line: 3,
893
+ column: 19
895
894
  }
896
895
  ],
897
896
  options: [{ fixSameNames: true }],
898
897
  output: `
899
- class ObjectA { camel_case = deferA }
900
- class ObjectB { snake_case = pending_a }
901
- var pending_a
902
- class ObjectC { snake_case = pending_a }
898
+ class ObjectB { camelCase = camelCase2 }
899
+ var camel_case, camel_case2
903
900
  `,
904
901
  parserOptions: { ecmaVersion: "latest" }
905
902
  },