@produtype/core 1.17.0 → 1.17.2

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.
@@ -45,13 +45,30 @@ const PATTERN_DECLARATION = /^(?:const\s+\w+(?:\s*:[^=]+)?\s*=\s*)?\/(?:[^/\\]|\
45
45
  * and `"access-control-allow-origin"` are one string spelled three ways. A trailing
46
46
  * comment is dropped first; Go puts the documentation link on the same line.
47
47
  */
48
+ /**
49
+ * A header name, in the shape the protocol writes them.
50
+ *
51
+ * Radarr shortens its constants — `public const string AllowOrigin =
52
+ * "Access-Control-Allow-Origin";` — so the two halves do not match and the
53
+ * spells-its-own-name test says nothing. It is the same table: five lines naming five
54
+ * headers, and the policy that matters is `builder.AllowAnyOrigin()` in `Startup.cs`,
55
+ * two files away.
56
+ *
57
+ * Hyphenated capitalised words are how HTTP writes a header and almost nothing else
58
+ * is written that way. It is required to be the whole value of a declaration, so a
59
+ * line that *sends* one — `res.setHeader('Access-Control-Allow-Origin', origin)` —
60
+ * has other arguments and is untouched.
61
+ */
62
+ const HTTP_HEADER_NAME = /^[A-Z][A-Za-z0-9]*(?:-[A-Z][A-Za-z0-9]*)+$/;
48
63
  function spellsItsOwnName(trimmed) {
49
64
  const withoutComment = trimmed.replace(/\s*(\/\/|#).*$/, '').replace(/[,;]\s*$/, '');
50
- const assignment = /^(?:const|let|var|final|static|public|private)?\s*([A-Za-z_][\w.]*)\s*(?::\s*[\w<>[\].]+)?\s*=\s*(['"`])([^'"`]+)\2$/.exec(withoutComment);
65
+ const assignment = /^(?:(?:public|private|protected|internal|export|const|let|var|final|static|readonly|string)\s+)*([A-Za-z_][\w.]*)\s*(?::\s*[\w<>[\].]+)?\s*=\s*(['"`])([^'"`]+)\2$/.exec(withoutComment);
51
66
  if (!assignment)
52
67
  return false;
53
68
  const plain = (value) => value.toLowerCase().replace(/[-_.\s]/g, '');
54
- return plain(assignment[1]) === plain(assignment[3]);
69
+ const declared = /^\s*(?:public|private|protected|internal|export|const|let|var|final|static|readonly)\b/.test(withoutComment);
70
+ return plain(assignment[1]) === plain(assignment[3])
71
+ || (declared && HTTP_HEADER_NAME.test(assignment[3]));
55
72
  }
56
73
  /**
57
74
  * A name given a type, rather than a value.
@@ -82,7 +99,7 @@ function spellsItsOwnName(trimmed) {
82
99
  * those really do introduce a declaration.
83
100
  */
84
101
  const STATEMENT_KEYWORD = /^(?:import|package|from|export|return|case|new|type|class|struct|interface|enum|func|fun|def|public|private|protected|internal|throw|throws|extends|implements|use|using|namespace|module|require|await|yield|delete|typeof|instanceof|in|is|as|if|else|for|while|switch|do|try|catch|finally|with|assert|raise|lambda|val|const)\b/;
85
- const TYPE_DECLARATION = /^(?:var\s+|let\s+|readonly\s+)?\w+\??\s*(?::\s*|\s+)(?:\[\]|\*|Array<|Map<|\bstring\b|\bnumber\b|\bboolean\b|\bbool\b|\bany\b|\bunknown\b|\bvoid\b|[A-Z])[\w.<>[\]|&\s]*;?$/;
102
+ const TYPE_DECLARATION = /^(?:var\s+|let\s+|readonly\s+)?\w+\??\s*(?::\s*|\s+)(?:\[\]|\*|Array<|Map<|\bstring\b|\bnumber\b|\bboolean\b|\bbool\b|\bany\b|\bunknown\b|\bvoid\b|[A-Z])[\w.<>[\]|&*\s]*;?$/;
86
103
  /**
87
104
  * Prose about the code, rather than the code.
88
105
  *
@@ -113,9 +130,22 @@ const COMMENT_LINE = /^(?:\/\/|\/\*|\*\/?|#(?![![])(?!!)|<!--|--\s)/;
113
130
  *
114
131
  * Nothing in the shape of the line tells the two apart, so the rule is not made.
115
132
  */
133
+ /**
134
+ * Two shapes the first version of this let through, both found in caddy.
135
+ *
136
+ * `allowedOrigins []*url.URL` is a struct field and the type is a pointer, which the
137
+ * character class did not allow — so a declaration was cited as a cross-origin
138
+ * decision. `AllowDomain []string // FIXME: this option is from legacy` is the same
139
+ * thing with gitea's note after it, and the rule required the line to end at the
140
+ * type.
141
+ *
142
+ * A trailing comment is dropped before the test, exactly as the self-naming rule
143
+ * drops it, and `*` and `&` join the characters a type may be written with.
144
+ */
116
145
  function declaresAType(trimmed) {
117
- const withoutDeclarator = trimmed.replace(/^(?:var|let|readonly)\s+/, '');
118
- return !STATEMENT_KEYWORD.test(withoutDeclarator) && TYPE_DECLARATION.test(trimmed);
146
+ const withoutComment = trimmed.replace(/\s*(?:\/\/|#).*$/, '').trimEnd();
147
+ const withoutDeclarator = withoutComment.replace(/^(?:var|let|readonly)\s+/, '');
148
+ return !STATEMENT_KEYWORD.test(withoutDeclarator) && TYPE_DECLARATION.test(withoutComment);
119
149
  }
120
150
  function declaresRatherThanDoes(line) {
121
151
  const trimmed = line.trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@produtype/core",
3
- "version": "1.17.0",
3
+ "version": "1.17.2",
4
4
  "description": "Deterministic CLI and library that analyzes a web application repository and reports how far it is from production-ready for the kind of product it is meant to be.",
5
5
  "license": "MIT",
6
6
  "bin": {