eslint-plugin-crisp 1.0.23 → 1.0.26

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-crisp",
3
- "version": "1.0.23",
3
+ "version": "1.0.26",
4
4
  "description": "Custom EsLint Rules for Crisp",
5
5
  "main": "index.js",
6
6
  "author": "Crisp IM SAS",
@@ -19,8 +19,23 @@ module.exports = {
19
19
  return;
20
20
  }
21
21
 
22
- const parsed = doctrine.parse(jsDocComment.value, { unwrap: true });
23
- const jsdocParams = parsed.tags.filter((tag) => tag.title === "param");
22
+ const parsed = doctrine.parse(jsDocComment.value, {
23
+ unwrap: true,
24
+ sloppy: true,
25
+ tags: ["param"]
26
+ });
27
+ let jsdocParams = parsed.tags;
28
+
29
+ // Remove "parent" params (i.e. 'payload' for 'payload.context'), \
30
+ // otherwise we end up with discrepancies between `jsdocParams` and \
31
+ // and `node.params`
32
+ jsdocParams = jsdocParams.filter((item, index, self) => {
33
+ // Check if next item exists and its name begins with current item's name followed by a dot
34
+ return !(
35
+ self[index + 1] &&
36
+ self[index + 1].name.startsWith(item.name + '.')
37
+ );
38
+ });
24
39
 
25
40
  node.params.forEach((param, i) => {
26
41
  // If there's a corresponding JSDoc parameter
@@ -30,11 +45,16 @@ module.exports = {
30
45
  });
31
46
 
32
47
  function checkNode(node, jsdocParam, jsdocParams) {
33
- if (node.type === "AssignmentPattern" && !/^\[.*\]$/.test(jsdocParam.name)) {
48
+ if (node.type === "AssignmentPattern" && jsdocParam.type.type !== "OptionalType") {
34
49
  context.report({
35
50
  node,
36
51
  message: "Optional parameters in JSDoc should be surrounded by brackets"
37
52
  });
53
+ } else if (jsdocParam.type.type === "OptionalType" && node.type !== "AssignmentPattern") {
54
+ context.report({
55
+ node,
56
+ message: "Non-optional parameters in JSDoc should not be surrounded by brackets"
57
+ });
38
58
  } else if (node.type === "ObjectPattern") {
39
59
  node.properties.forEach((property) => {
40
60
  const nestedJsdocParam = jsdocParams.find((param) => {
@@ -17,6 +17,12 @@ module.exports = {
17
17
 
18
18
  properties.slice(0, -1).forEach((property, index) => {
19
19
  const nextProperty = properties[index + 1];
20
+
21
+ // Ignore non-property values (e.g. spread expressions)
22
+ if (property.type !== "Property" || !nextProperty || nextProperty.type !== "Property") {
23
+ return;
24
+ }
25
+
20
26
  if (property.key.name > nextProperty.key.name) {
21
27
  context.report({
22
28
  node: nextProperty,