@colixsystems/widget-sdk 0.355.0 → 0.355.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.
package/README.md CHANGED
@@ -91,7 +91,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
91
91
 
92
92
  ## Status
93
93
 
94
- `v0.355.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
94
+ `v0.355.1` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
95
+
96
+ ### What's new in 0.355.1 (contract 1.291.0)
97
+
98
+ **The date rule reads date-fns options it cannot see.** `date-shown-fixed-format` no longer flags a date-fns pattern that prints words when the call's options may carry the app's locale without spelling it out: options held in a variable (`format(d, "PPP", opts)`), an options object with a spread (`{ ...dfOptions }`), or a call with no `locale` after date-fns `setDefaultOptions` was given one (`setDefaultOptions({ locale: appLocale })`, imported by name, by default from `date-fns/setDefaultOptions` or through a namespace). A fixed `date-fns/locale` import is still one language, so `setDefaultOptions({ locale: sv })` or `{ ...dfOptions, locale: sv }` still flags, and a numeric day-before-month pattern flags whatever the options. Fewer findings, no new ones.
95
99
 
96
100
  ### What's new in 0.355.0 (contract 1.291.0)
97
101
 
package/dist/linter.cjs CHANGED
@@ -2012,7 +2012,14 @@ const MEMBER_CALL_RE = /(?<![\w$.])([\w$]+)\s*\.\s*([\w$]+)\s*\(/g;
2012
2012
 
2013
2013
  /** date-fns formatter names and namespaces, and the locale objects it was given. */
2014
2014
  function _dateFnsImports(strings) {
2015
- const imports = { formatters: new Map(), namespaces: new Set(), locales: new Set(), localeNamespaces: new Set() };
2015
+ const imports = {
2016
+ formatters: new Map(),
2017
+ namespaces: new Set(),
2018
+ locales: new Set(),
2019
+ localeNamespaces: new Set(),
2020
+ defaultSetters: new Set(),
2021
+ defaultAppLocale: false,
2022
+ };
2016
2023
  for (const [, ns, deflt, named, , subpath = ""] of strings.matchAll(DATE_FNS_IMPORT_RE)) {
2017
2024
  if (subpath.startsWith("/locale")) {
2018
2025
  if (ns) imports.localeNamespaces.add(ns);
@@ -2025,9 +2032,11 @@ function _dateFnsImports(strings) {
2025
2032
  }
2026
2033
  if (ns && !subpath) imports.namespaces.add(ns);
2027
2034
  if (deflt && DATE_FNS_FORMATTERS.has(subpath.slice(1))) imports.formatters.set(deflt, DATE_FNS_FORMATTERS.get(subpath.slice(1)));
2035
+ if (deflt && subpath === "/setDefaultOptions") imports.defaultSetters.add(deflt);
2028
2036
  for (const spec of (named || "").split(",")) {
2029
2037
  const [imported, local] = spec.trim().split(/\s+as\s+/);
2030
2038
  if (DATE_FNS_FORMATTERS.has(imported)) imports.formatters.set(local || imported, DATE_FNS_FORMATTERS.get(imported));
2039
+ if (imported === "setDefaultOptions") imports.defaultSetters.add(local || imported);
2031
2040
  }
2032
2041
  }
2033
2042
  return imports;
@@ -2051,12 +2060,16 @@ function _callArgs(code, openParen) {
2051
2060
 
2052
2061
  const _stringLiteral = (text) => /^\s*(["'`])((?:(?!\1)[^$\\]){1,80})\1/.exec(text)?.[2] ?? null;
2053
2062
 
2054
- /** True when the call's options pass a locale that is not one fixed date-fns locale. */
2063
+ /**
2064
+ * True when the options may carry a locale that is not one fixed date-fns locale:
2065
+ * named in them, in an object held elsewhere or spread in, or set by setDefaultOptions.
2066
+ */
2055
2067
  function _appLocaleOption(options, imports) {
2056
2068
  const m = LOCALE_OPTION_RE.exec(options);
2057
- if (!m) return false;
2058
- if (!m[1]) return true;
2059
- return !(imports.locales.has(m[1]) || (imports.localeNamespaces.has(m[1]) && m[2]));
2069
+ if (m) return !m[1] || !(imports.locales.has(m[1]) || (imports.localeNamespaces.has(m[1]) && m[2]));
2070
+ const literal = options.trimStart();
2071
+ if (literal && (!literal.startsWith("{") || literal.includes("..."))) return true;
2072
+ return imports.defaultAppLocale;
2060
2073
  }
2061
2074
 
2062
2075
  /** A date-fns pattern that prints words without the app's locale, or a day and month not year-first. */
@@ -2102,6 +2115,20 @@ function _fixedDateFormatRules(source) {
2102
2115
  const options = starts.length > patternArg + 1 ? code.slice(starts[patternArg + 1], end) : "";
2103
2116
  if (pattern && _fixedDatePattern(pattern, _appLocaleOption(options, imports))) report(m.index, `pattern "${pattern}"`);
2104
2117
  };
2118
+ const setsAppLocale = (m) => {
2119
+ const { starts, end } = _callArgs(code, m.index + m[0].length - 1);
2120
+ return _appLocaleOption(code.slice(starts[0], end), imports);
2121
+ };
2122
+ if (imports.defaultSetters.size > 0) {
2123
+ for (const m of code.matchAll(CALL_RE)) {
2124
+ if (imports.defaultSetters.has(m[1]) && setsAppLocale(m)) imports.defaultAppLocale = true;
2125
+ }
2126
+ }
2127
+ if (imports.namespaces.size > 0) {
2128
+ for (const m of code.matchAll(MEMBER_CALL_RE)) {
2129
+ if (imports.namespaces.has(m[1]) && m[2] === "setDefaultOptions" && setsAppLocale(m)) imports.defaultAppLocale = true;
2130
+ }
2131
+ }
2105
2132
  if (imports.formatters.size > 0) {
2106
2133
  for (const m of code.matchAll(CALL_RE)) {
2107
2134
  if (imports.formatters.has(m[1])) checkCall(m, imports.formatters.get(m[1]));
package/dist/linter.js CHANGED
@@ -2007,7 +2007,14 @@ const MEMBER_CALL_RE = /(?<![\w$.])([\w$]+)\s*\.\s*([\w$]+)\s*\(/g;
2007
2007
 
2008
2008
  /** date-fns formatter names and namespaces, and the locale objects it was given. */
2009
2009
  function _dateFnsImports(strings) {
2010
- const imports = { formatters: new Map(), namespaces: new Set(), locales: new Set(), localeNamespaces: new Set() };
2010
+ const imports = {
2011
+ formatters: new Map(),
2012
+ namespaces: new Set(),
2013
+ locales: new Set(),
2014
+ localeNamespaces: new Set(),
2015
+ defaultSetters: new Set(),
2016
+ defaultAppLocale: false,
2017
+ };
2011
2018
  for (const [, ns, deflt, named, , subpath = ""] of strings.matchAll(DATE_FNS_IMPORT_RE)) {
2012
2019
  if (subpath.startsWith("/locale")) {
2013
2020
  if (ns) imports.localeNamespaces.add(ns);
@@ -2020,9 +2027,11 @@ function _dateFnsImports(strings) {
2020
2027
  }
2021
2028
  if (ns && !subpath) imports.namespaces.add(ns);
2022
2029
  if (deflt && DATE_FNS_FORMATTERS.has(subpath.slice(1))) imports.formatters.set(deflt, DATE_FNS_FORMATTERS.get(subpath.slice(1)));
2030
+ if (deflt && subpath === "/setDefaultOptions") imports.defaultSetters.add(deflt);
2023
2031
  for (const spec of (named || "").split(",")) {
2024
2032
  const [imported, local] = spec.trim().split(/\s+as\s+/);
2025
2033
  if (DATE_FNS_FORMATTERS.has(imported)) imports.formatters.set(local || imported, DATE_FNS_FORMATTERS.get(imported));
2034
+ if (imported === "setDefaultOptions") imports.defaultSetters.add(local || imported);
2026
2035
  }
2027
2036
  }
2028
2037
  return imports;
@@ -2046,12 +2055,16 @@ function _callArgs(code, openParen) {
2046
2055
 
2047
2056
  const _stringLiteral = (text) => /^\s*(["'`])((?:(?!\1)[^$\\]){1,80})\1/.exec(text)?.[2] ?? null;
2048
2057
 
2049
- /** True when the call's options pass a locale that is not one fixed date-fns locale. */
2058
+ /**
2059
+ * True when the options may carry a locale that is not one fixed date-fns locale:
2060
+ * named in them, in an object held elsewhere or spread in, or set by setDefaultOptions.
2061
+ */
2050
2062
  function _appLocaleOption(options, imports) {
2051
2063
  const m = LOCALE_OPTION_RE.exec(options);
2052
- if (!m) return false;
2053
- if (!m[1]) return true;
2054
- return !(imports.locales.has(m[1]) || (imports.localeNamespaces.has(m[1]) && m[2]));
2064
+ if (m) return !m[1] || !(imports.locales.has(m[1]) || (imports.localeNamespaces.has(m[1]) && m[2]));
2065
+ const literal = options.trimStart();
2066
+ if (literal && (!literal.startsWith("{") || literal.includes("..."))) return true;
2067
+ return imports.defaultAppLocale;
2055
2068
  }
2056
2069
 
2057
2070
  /** A date-fns pattern that prints words without the app's locale, or a day and month not year-first. */
@@ -2097,6 +2110,20 @@ function _fixedDateFormatRules(source) {
2097
2110
  const options = starts.length > patternArg + 1 ? code.slice(starts[patternArg + 1], end) : "";
2098
2111
  if (pattern && _fixedDatePattern(pattern, _appLocaleOption(options, imports))) report(m.index, `pattern "${pattern}"`);
2099
2112
  };
2113
+ const setsAppLocale = (m) => {
2114
+ const { starts, end } = _callArgs(code, m.index + m[0].length - 1);
2115
+ return _appLocaleOption(code.slice(starts[0], end), imports);
2116
+ };
2117
+ if (imports.defaultSetters.size > 0) {
2118
+ for (const m of code.matchAll(CALL_RE)) {
2119
+ if (imports.defaultSetters.has(m[1]) && setsAppLocale(m)) imports.defaultAppLocale = true;
2120
+ }
2121
+ }
2122
+ if (imports.namespaces.size > 0) {
2123
+ for (const m of code.matchAll(MEMBER_CALL_RE)) {
2124
+ if (imports.namespaces.has(m[1]) && m[2] === "setDefaultOptions" && setsAppLocale(m)) imports.defaultAppLocale = true;
2125
+ }
2126
+ }
2100
2127
  if (imports.formatters.size > 0) {
2101
2128
  for (const m of code.matchAll(CALL_RE)) {
2102
2129
  if (imports.formatters.has(m[1])) checkCall(m, imports.formatters.get(m[1]));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.355.0",
3
+ "version": "0.355.1",
4
4
  "description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
5
5
  "repository": {
6
6
  "type": "git",