@longzai-intelligence-oxlint/stylistic-plugin 0.1.36 → 0.1.38

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.
Files changed (2) hide show
  1. package/dist/index.js +9 -9
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import{defineRule as e,eslintCompatPlugin as t}from"@oxlint/plugins";import{parseSeparatorComment as n}from"@longzai-intelligence-oxlint/tsdoc-plugin";function r(){return{isBlockStart:!1,isBlockEnd:!1,isObjectStart:!1,isObjectEnd:!1,isArrayStart:!1,isArrayEnd:!1,isClassStart:!1,isClassEnd:!1,isInterfaceStart:!1,isInterfaceEnd:!1,isTypeStart:!1,isTypeEnd:!1,isEnumStart:!1,isEnumEnd:!1,isModuleStart:!1,isModuleEnd:!1,isFunctionStart:!1,isFunctionEnd:!1}}function i(e){return!!(e.includes(`type `)||e.includes(`extends {`)||e.includes(`type{`)||e.includes(`Array<{`)||e.includes(`Promise<{`)||e.includes(`<{`)||e.includes(`| {`)||e.includes(`as {`)||e.includes(`Record<{`)||e.includes(`Partial<{`)||e.includes(`Required<{`)||e.includes(`Pick<{`)||e.includes(`Omit<{`)||e.includes(`& {`))}function a(e,t){for(let n=2;n<=5&&t>n;n++){let r=e[t-n-1];if(r){let e=r.trimEnd();if(e.includes(`Record<{`)||e.includes(`Partial<{`)||e.includes(`Required<{`)||e.includes(`Pick<{`)||e.includes(`Omit<{`)||e.includes(`Array<{`)||e.includes(`Promise<{`)||e.includes(`type `)||e.includes(`interface `))return!0}}return!1}function o(e){return e.endsWith(`) {`)||e.endsWith(`){`)||/\)\s*(?::\s*[^{]+)?\{/.test(e)||e.includes(`=> {`)}function s(e){return!!(e.endsWith(`) {`)||e.endsWith(`){`)||e===`{`||/: [^{]+ \{$/.test(e)||/\)\s*(?::\s*[^{]+)?\{/.test(e)||e.endsWith(`}> {`)||e===`> {`||e.includes(`try {`)||e.includes(`catch {`)||e.includes(`finally {`)||e.includes(`=> {`)||e.includes(`else {`)||/^\w+\s*\{$/.test(e)||/^\| .+ \{$/.test(e))}function c(e){let t=e.includes(`namespace `)||e.includes(`namespace{`),n=e.startsWith(`declare global`)||e.startsWith(`declare module`);return e.includes(`module `)||e.includes(`module{`)||t||n}function l(e,t){for(let n=2;n<=10&&t>n;n++){let r=e[t-n-1];if(r){let e=r.trim();if(e.includes(`class `)||e.includes(`class{`))return!0}}return!1}function ee(e){let t=/\w\(\{$/.test(e),n=e.endsWith(`, {`),r=/=>\s*\(\{$/.test(e),i=e.includes(`export default {`);return e.includes(`: {`)||e.endsWith(`= {`)||t||n||r||i}function u(e,t,n,r){i(t)?e.isTypeStart=!0:t.trim()===`{`?e[a(n,r)?`isTypeStart`:`isBlockStart`]=!0:t.includes(`interface `)||t.includes(`interface{`)?e.isInterfaceStart=!0:t.includes(`enum `)||t.includes(`enum{`)?e.isEnumStart=!0:c(t)?e.isModuleStart=!0:t.includes(`class `)||t.includes(`class{`)||t===`> {`?e.isClassStart=!0:s(t)?(e.isBlockStart=!0,o(t)&&(e.isFunctionStart=!0)):ee(t)?e.isObjectStart=!0:t.includes(`: [`)||t.endsWith(`= [`)||t.endsWith(`[`)?e.isArrayStart=!0:l(n,r)&&(e.isClassStart=!0)}function d(e,t,n){if(t<=1)return;let r=t-2;for(;r>=0;){let e=n[r];if(e&&e.trim().length>0)break;r--}if(r<0)return;let i=n[r];if(!i)return;let a=i.trim();a.endsWith(`{`)||/>+\s*\{\s*$/.test(a)?u(e,a,n,t):a.endsWith(`(`)||a.endsWith(`>`)?e.isBlockStart=!0:a.endsWith(`[`)&&(e.isArrayStart=!0)}function f(e,t,n){if(t>=n.length)return;let r=n[t];if(!r)return;let i=r.trimStart();if(i===`}`){e.isBlockEnd=!0,e.isObjectEnd=!0,e.isClassEnd=!0,e.isInterfaceEnd=!0,e.isTypeEnd=!0,e.isEnumEnd=!0,e.isModuleEnd=!0,e.isFunctionEnd=!0;return}if(i===`};`){e.isBlockEnd=!0,e.isObjectEnd=!0,e.isClassEnd=!0,e.isInterfaceEnd=!0,e.isTypeEnd=!0,e.isEnumEnd=!0,e.isModuleEnd=!0,e.isFunctionEnd=!0;return}if(i.startsWith(`];`)){e.isArrayEnd=!0;return}}function p(e,t){let n=r(),i=e.loc.start.line,a=e.loc.end.line;return d(n,i,t),f(n,a,t),n}const m={beforeBlockComment:!0,afterBlockComment:!1,beforeLineComment:!1,afterLineComment:!1,allowBlockStart:!1,allowBlockEnd:!1,allowObjectStart:!1,allowObjectEnd:!1,allowArrayStart:!1,allowArrayEnd:!1,allowClassStart:!1,allowClassEnd:!1,allowInterfaceStart:!1,allowInterfaceEnd:!1,allowTypeStart:!1,allowTypeEnd:!1,allowEnumStart:!1,allowEnumEnd:!1,allowModuleStart:!1,allowModuleEnd:!1,allowFunctionStart:!1,allowFunctionEnd:!1,ignorePattern:void 0,applyDefaultIgnorePatterns:!0};function h(e,t){if(e.loc.start.line<=1)return!1;let n=g(e.loc.start.line,t);return n?/\w+=\{$/.test(n):!1}function te(e,t){if(e.loc.start.line<=1)return!1;let n=g(e.loc.start.line,t);if(!n||!(n===`}`||/^\w+=("[^"]*"|'[^']*')$/.test(n)||/^\w+=\{.+\}$/.test(n)||/^<[A-Z]\w*$/.test(n)||/^\w+:$/.test(n)))return!1;let r=_(e.loc.end.line,t);return r?/^\w+=/.test(r)||/^\/?>$/.test(r)||r.startsWith(`/>`)||r.startsWith(`(`)||r.startsWith(`<`):!1}function g(e,t){let n=e-2;for(;n>=0;){let e=t[n];if(e&&e.trim().length>0)return e.trim();n--}return null}function _(e,t){let n=e;for(;n<t.length;){let e=t[n];if(e&&e.trim().length>0)return e.trim();n++}return null}function v(e,t){let n=t[e.loc.start.line-1];return n?n.slice(0,e.loc.start.column).trim().length>0:!1}function y(e,t){if(t.length===0)return!1;let n=t[t.length-1];return n?n.loc.end.line+1>=e.loc.start.line:!1}const b=[/^eslint/i,/^jshint/i,/^jslint/i,/^istanbul/i,/^global/i,/^exported/i,/^jscs/i];function x(e,t){let n=e.value.trim();if(t.applyDefaultIgnorePatterns!==!1){for(let e of b)if(e.test(n))return!0}return!!(t.ignorePattern&&new RegExp(t.ignorePattern,`u`).test(n))}function S(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function C(e,t,n){let r=t[n];typeof r==`boolean`&&(e[n]=r)}function w(e,t){C(e,t,`beforeBlockComment`),C(e,t,`afterBlockComment`),C(e,t,`beforeLineComment`),C(e,t,`afterLineComment`),C(e,t,`allowBlockStart`),C(e,t,`allowBlockEnd`),C(e,t,`allowObjectStart`),C(e,t,`allowObjectEnd`),C(e,t,`allowArrayStart`),C(e,t,`allowArrayEnd`),C(e,t,`allowClassStart`),C(e,t,`allowClassEnd`),C(e,t,`allowInterfaceStart`),C(e,t,`allowInterfaceEnd`),C(e,t,`allowTypeStart`),C(e,t,`allowTypeEnd`),C(e,t,`allowEnumStart`),C(e,t,`allowEnumEnd`),C(e,t,`allowModuleStart`),C(e,t,`allowModuleEnd`),C(e,t,`allowFunctionStart`),C(e,t,`allowFunctionEnd`),C(e,t,`applyDefaultIgnorePatterns`)}function T(e,t,n){let r=t[n];typeof r==`string`&&(e[n]=r)}function E(e){let t={...m};return S(e)?(w(t,e),T(t,e,`ignorePattern`),t):t}function D(e,t){return e<=1||t[e-2]?.trim()===``}function O(e,t){return e>=t.length||t[e]?.trim()===``}function k(e,t){return e.isBlockStart&&(t.allowBlockStart??!1)||e.isObjectStart&&(t.allowObjectStart??!1)||e.isArrayStart&&(t.allowArrayStart??!1)||e.isClassStart&&(t.allowClassStart??!1)||e.isInterfaceStart&&(t.allowInterfaceStart??!1)||e.isTypeStart&&(t.allowTypeStart??!1)||e.isEnumStart&&(t.allowEnumStart??!1)||e.isModuleStart&&(t.allowModuleStart??!1)||e.isFunctionStart&&(t.allowFunctionStart??!1)}function A(e,t){return e.isBlockEnd&&(t.allowBlockEnd??!1)||e.isObjectEnd&&(t.allowObjectEnd??!1)||e.isArrayEnd&&(t.allowArrayEnd??!1)||e.isClassEnd&&(t.allowClassEnd??!1)||e.isInterfaceEnd&&(t.allowInterfaceEnd??!1)||e.isTypeEnd&&(t.allowTypeEnd??!1)||e.isEnumEnd&&(t.allowEnumEnd??!1)||e.isModuleEnd&&(t.allowModuleEnd??!1)||e.isFunctionEnd&&(t.allowFunctionEnd??!1)}function j(e,t,n,r,i){let a=e.type===`Block`;if(a&&n.beforeBlockComment||!a&&n.beforeLineComment){if(k(i,n))return;let o=e.loc.start.line;D(o,t)||r.report({loc:{start:e.loc.start,end:e.loc.start},message:a?`块注释前需要空行`:`行注释前需要空行`,fix:n=>{let r=0;for(let n=0;n<e.loc.start.line-1;n++)r+=(t[n]?.length??0)+1;return n.insertTextBeforeRange([r,r],`
2
- `)}})}}function M(e,t,n,r,i){let a=e.type===`Block`;if(a&&n.afterBlockComment||!a&&n.afterLineComment){if(A(i,n))return;let o=e.loc.end.line;O(o,t)||r.report({loc:{start:e.loc.end,end:e.loc.end},message:a?`块注释后需要空行`:`行注释后需要空行`,fix:t=>t.insertTextAfterRange([e.range[1],e.range[1]],`
3
- `)})}}function N(e,t,n,r,i=[],a=!1,o=!1){if(v(e,t)||x(e,n))return;let s=y(e,i),c=p(e,t),l=h(e,t)||te(e,t);!a&&!s&&!l&&j(e,t,n,r,c),o||M(e,t,n,r,c)}const P=e({meta:{type:`layout`,fixable:`whitespace`,docs:{description:`要求在注释前后有空行`},schema:[{type:`object`,properties:{beforeBlockComment:{type:`boolean`},afterBlockComment:{type:`boolean`},beforeLineComment:{type:`boolean`},afterLineComment:{type:`boolean`},allowBlockStart:{type:`boolean`},allowBlockEnd:{type:`boolean`},allowObjectStart:{type:`boolean`},allowObjectEnd:{type:`boolean`},allowArrayStart:{type:`boolean`},allowArrayEnd:{type:`boolean`},allowClassStart:{type:`boolean`},allowClassEnd:{type:`boolean`},allowInterfaceStart:{type:`boolean`},allowInterfaceEnd:{type:`boolean`},allowTypeStart:{type:`boolean`},allowTypeEnd:{type:`boolean`},allowEnumStart:{type:`boolean`},allowEnumEnd:{type:`boolean`},allowModuleStart:{type:`boolean`},allowModuleEnd:{type:`boolean`},allowFunctionStart:{type:`boolean`},allowFunctionEnd:{type:`boolean`},ignorePattern:{type:`string`},applyDefaultIgnorePatterns:{type:`boolean`}},additionalProperties:!1}]},createOnce(e){let t=[],n=[];return{Program(){let r=E(e.options?.[0]);t=e.sourceCode.text.split(`
4
- `),n=[];let i=e.sourceCode.getAllComments();for(let a=0;a<i.length;a++){let o=i[a];if(!o)continue;let s=i[a+1],c=s!==void 0&&s.loc.start.line<=o.loc.end.line+1;N(o,t,r,e,n,!1,c),n.push(o)}}}}}),F=[`eslint`,`oxlint`,`jshint`,`jslint`,`tslint`,`istanbul`,`global`,`exported`,`jscs`],I=[`<reference`,`<amd-module`,`<amd-dependency`,`@ts-`],ne=/^\*?\s*$/u,L=/^\s*$/u,R=`禁止双斜杠注释,只允许多行块注释`;function z(e){let t=e.value.trim(),n=t.replace(/^\/+/u,``).trim();return F.some(e=>t.startsWith(e))||I.some(e=>n.startsWith(e))}function B(e){return e.type===`Line`&&n(e.value)!==null}function V(e,t){let n=t[e.loc.start.line-1];if(!n)return` `.repeat(e.loc.start.column);let r=n.slice(0,e.loc.start.column);return r.trim().length>0?` `.repeat(e.loc.start.column):r}function H(e){let t=[];for(let n of e){let e=t[t.length-1];if(e){let t=e[e.length-1];if(t&&t.loc.end.line===n.loc.start.line-1){e.push(n);continue}}t.push([n])}return t}function U(e){return e.map(e=>e.value)}function W(e,t){return`/*\n${e.map(e=>{let n=e.trim();return n?`${t} * ${n}`:`${t} *`}).join(`
5
- `)}\n${t} */`}function G(e,t){let n=e.trim();return n?`/*\n${t} * ${n}\n${t} */`:`/*\n${t} */`}function K(e,t){let n=e.value.split(`
6
- `),r=0;for(let e=0;e<t;e++)r+=(n[e]?.length??0)+1;return e.range[0]+2+r}function q(e,t){let n=[],r=[];for(let i of e){if(v(i,t)){n.push({message:R,loc:{start:{...i.loc.start},end:{...i.loc.end}}});continue}r.push(i)}for(let e of H(r)){let r=e[0],i=e[e.length-1];if(!r||!i)continue;let a=V(r,t),o=U(e),s=o.some(e=>e.trim().startsWith(`/`));n.push({message:R,loc:{start:{...r.loc.start},end:{...i.loc.end}},fix:s?void 0:{range:[r.range[0],i.range[1]],text:W(o,a)}})}return n}function J(e,t){let n=[],r=e.value.split(`
7
- `),i=V(e,t);if(e.loc.start.line===e.loc.end.line)return n.push({message:`禁止单行块注释,注释须为多行星号块形态`,loc:{start:{...e.loc.start},end:{...e.loc.end}},fix:{range:[e.range[0],e.range[1]],text:G(e.value,i)}}),n;let a=r[0]??``;if(!ne.test(a)){let t=+!!a.startsWith(`*`);n.push({message:`多行块注释的首行应在 "/*" 后换行`,loc:{start:{...e.loc.start},end:{...e.loc.end}},fix:{range:[e.range[0]+2,e.range[0]+2+t],text:`\n${i} *`}})}for(let t=1;t<r.length-1;t++){let a=r[t]??``,o=a.trim();if(!o||o.startsWith(`*`))continue;let s=K(e,t),c=a.length-a.trimStart().length;n.push({message:`多行注释的中间行应以 "*" 开头`,loc:{start:{line:e.loc.start.line+t,column:0},end:{line:e.loc.start.line+t,column:a.length}},fix:{range:[s,s+c],text:`${i} * `}})}let o=r[r.length-1]??``;return L.test(o)||n.push({message:`多行块注释的末行应在 "*/" 前换行`,loc:{start:{...e.loc.start},end:{...e.loc.end}},fix:{range:[e.range[1]-2,e.range[1]-2],text:`\n${i} `}}),n}function Y(e,t){let n=[],r=[];for(let i of e)if(i.type!==`Shebang`&&!z(i)&&!B(i)){if(i.type===`Line`){r.push(i);continue}n.push(...J(i,t))}return n.push(...q(r,t)),n}const X=e({meta:{type:`layout`,fixable:`code`,docs:{description:`强制多行注释使用星号块样式`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments(),r=e.sourceCode.text,i=Y(n,r==null?[]:r.split(`
8
- `));for(let t of i){let{fix:n}=t;e.report({loc:t.loc,message:t.message,fix:n?e=>e.replaceTextRange(n.range,n.text):void 0})}}}}});function Z(e){return e.type===`ExportNamedDeclaration`||e.type===`ExportDefaultDeclaration`||e.type===`ExportAllDeclaration`}function re(e,t,n){if(n-t<=1)return!1;for(let r=t+1;r<n;r++)if(e[r-1]?.trim()===``)return!0;return!1}function ie(e){return e.type===`Program`}function ae(e,t,n){for(let r=1;r<e.length;r++){let i=e[r-1],a=e[r];if(i!==void 0&&a!==void 0&&Z(i)&&Z(a)){let e=i.loc.end.line,r=a.loc.start.line;re(t,e,r)||n.report({loc:a.loc.start,message:`export 语句之间需要空行`})}}}const Q={"multiline-comment-style":X,"lines-around-comment":P,"padding-line-between-statements":e({meta:{type:`layout`,docs:{description:`要求在 export 语句之间有空行`}},createOnce(e){return{Program(t){let n=e.sourceCode.text.split(`
9
- `),r=ie(t)?t:null;r&&ae(r.body,n,e)}}}})},$=t({meta:{name:`@longzai-intelligence-oxlint/stylistic-plugin`},rules:Q});export{$ as default,$ as stylisticPlugin,Q as stylisticRules};
1
+ import{defineRule as e,eslintCompatPlugin as t}from"@oxlint/plugins";import{parseSeparatorComment as n}from"@longzai-intelligence-oxlint/tsdoc-plugin";function r(){return{isBlockStart:!1,isBlockEnd:!1,isObjectStart:!1,isObjectEnd:!1,isArrayStart:!1,isArrayEnd:!1,isClassStart:!1,isClassEnd:!1,isInterfaceStart:!1,isInterfaceEnd:!1,isTypeStart:!1,isTypeEnd:!1,isEnumStart:!1,isEnumEnd:!1,isModuleStart:!1,isModuleEnd:!1,isFunctionStart:!1,isFunctionEnd:!1}}function i(e){return!!(e.includes(`type `)||e.includes(`extends {`)||e.includes(`type{`)||e.includes(`Array<{`)||e.includes(`Promise<{`)||e.includes(`<{`)||e.includes(`| {`)||e.includes(`as {`)||e.includes(`Record<{`)||e.includes(`Partial<{`)||e.includes(`Required<{`)||e.includes(`Pick<{`)||e.includes(`Omit<{`)||e.includes(`& {`))}function a(e,t){for(let n=2;n<=5&&t>n;n++){let r=e[t-n-1];if(r){let e=r.trimEnd();if(e.includes(`Record<{`)||e.includes(`Partial<{`)||e.includes(`Required<{`)||e.includes(`Pick<{`)||e.includes(`Omit<{`)||e.includes(`Array<{`)||e.includes(`Promise<{`)||e.includes(`type `)||e.includes(`interface `))return!0}}return!1}function o(e){return e.endsWith(`) {`)||e.endsWith(`){`)||/\)\s*(?::\s*[^{]+)?\{/.test(e)||e.includes(`=> {`)}function s(e){return!!(e.endsWith(`) {`)||e.endsWith(`){`)||e===`{`||/: [^{]+ \{$/.test(e)||/\)\s*(?::\s*[^{]+)?\{/.test(e)||e.endsWith(`}> {`)||e===`> {`||e.includes(`try {`)||e.includes(`catch {`)||e.includes(`finally {`)||e.includes(`=> {`)||e.includes(`else {`)||/^\w+\s*\{$/.test(e)||/^\| .+ \{$/.test(e))}function c(e){let t=e.includes(`namespace `)||e.includes(`namespace{`),n=e.startsWith(`declare global`)||e.startsWith(`declare module`);return e.includes(`module `)||e.includes(`module{`)||t||n}function l(e,t){for(let n=2;n<=10&&t>n;n++){let r=e[t-n-1];if(r){let e=r.trim();if(e.includes(`class `)||e.includes(`class{`))return!0}}return!1}function u(e){let t=/\w\(\{$/.test(e),n=e.endsWith(`, {`),r=/=>\s*\(\{$/.test(e),i=e.includes(`export default {`);return e.includes(`: {`)||e.endsWith(`= {`)||t||n||r||i}function d(e,t,n,r){i(t)?e.isTypeStart=!0:t.trim()===`{`?e[a(n,r)?`isTypeStart`:`isBlockStart`]=!0:t.includes(`interface `)||t.includes(`interface{`)?e.isInterfaceStart=!0:t.includes(`enum `)||t.includes(`enum{`)?e.isEnumStart=!0:c(t)?e.isModuleStart=!0:t.includes(`class `)||t.includes(`class{`)||t===`> {`?e.isClassStart=!0:s(t)?(e.isBlockStart=!0,o(t)&&(e.isFunctionStart=!0)):u(t)?e.isObjectStart=!0:t.includes(`: [`)||t.endsWith(`= [`)||t.endsWith(`[`)?e.isArrayStart=!0:l(n,r)&&(e.isClassStart=!0)}function f(e,t,n){if(t<=1)return;let r=t-2;for(;r>=0;){let e=n[r];if(e&&e.trim().length>0)break;r--}if(r<0)return;let i=n[r];if(!i)return;let a=i.trim();a.endsWith(`{`)||/>+\s*\{\s*$/.test(a)?d(e,a,n,t):a.endsWith(`(`)||a.endsWith(`>`)?e.isBlockStart=!0:a.endsWith(`[`)&&(e.isArrayStart=!0)}function p(e,t,n){if(t>=n.length)return;let r=n[t];if(!r)return;let i=r.trimStart();i===`}`||i===`};`?(e.isBlockEnd=!0,e.isObjectEnd=!0,e.isClassEnd=!0,e.isInterfaceEnd=!0,e.isTypeEnd=!0,e.isEnumEnd=!0,e.isModuleEnd=!0,e.isFunctionEnd=!0):i.startsWith(`];`)&&(e.isArrayEnd=!0)}function m(e,t){let n=r(),i=e.loc.start.line,a=e.loc.end.line;return f(n,i,t),p(n,a,t),n}const h={beforeBlockComment:!0,afterBlockComment:!1,beforeLineComment:!1,afterLineComment:!1,allowBlockStart:!1,allowBlockEnd:!1,allowObjectStart:!1,allowObjectEnd:!1,allowArrayStart:!1,allowArrayEnd:!1,allowClassStart:!1,allowClassEnd:!1,allowInterfaceStart:!1,allowInterfaceEnd:!1,allowTypeStart:!1,allowTypeEnd:!1,allowEnumStart:!1,allowEnumEnd:!1,allowModuleStart:!1,allowModuleEnd:!1,allowFunctionStart:!1,allowFunctionEnd:!1,ignorePattern:void 0,applyDefaultIgnorePatterns:!0};function ee(e,t){if(e.loc.start.line<=1)return!1;let n=g(e.loc.start.line,t);return n?/\w+=\{$/.test(n):!1}function te(e,t){if(e.loc.start.line<=1)return!1;let n=g(e.loc.start.line,t);if(!n||!(n===`}`||/^\w+=("[^"]*"|'[^']*')$/.test(n)||/^\w+=\{.+\}$/.test(n)||/^<[A-Z]\w*$/.test(n)||/^\w+:$/.test(n)))return!1;let r=_(e.loc.end.line,t);return r?/^\w+=/.test(r)||/^\/?>$/.test(r)||r.startsWith(`/>`)||r.startsWith(`(`)||r.startsWith(`<`):!1}const ne=/(?:,|:|\?|=>|&&|\|\||=|[+*/%&|^<-])$/u;function re(e,t){if(e.loc.start.line<=1)return!1;let n=y(e.loc.start.line,t);return n?ne.test(n):!1}function g(e,t){let n=e-2;for(;n>=0;){let e=t[n];if(e&&e.trim().length>0)return e.trim();n--}return null}function _(e,t){let n=e;for(;n<t.length;){let e=t[n];if(e&&e.trim().length>0)return e.trim();n++}return null}function v(e){return e.startsWith(`//`)||e.startsWith(`/*`)||e.startsWith(`*`)}function y(e,t){let n=e-2;for(;n>=0;){let e=t[n];if(e&&e.trim().length>0&&!v(e.trim()))return e.trim();n--}return null}function b(e,t){let n=t[e.loc.start.line-1];return n?n.slice(0,e.loc.start.column).trim().length>0:!1}function x(e,t){if(t.length===0)return!1;let n=t[t.length-1];return n?n.loc.end.line+1>=e.loc.start.line:!1}const S=[/^eslint/i,/^jshint/i,/^jslint/i,/^istanbul/i,/^global/i,/^exported/i,/^jscs/i];function C(e,t){let n=e.value.trim();if(t.applyDefaultIgnorePatterns!==!1){for(let e of S)if(e.test(n))return!0}return!!(t.ignorePattern&&new RegExp(t.ignorePattern,`u`).test(n))}function w(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function T(e,t,n){let r=t[n];typeof r==`boolean`&&(e[n]=r)}function E(e,t){T(e,t,`beforeBlockComment`),T(e,t,`afterBlockComment`),T(e,t,`beforeLineComment`),T(e,t,`afterLineComment`),T(e,t,`allowBlockStart`),T(e,t,`allowBlockEnd`),T(e,t,`allowObjectStart`),T(e,t,`allowObjectEnd`),T(e,t,`allowArrayStart`),T(e,t,`allowArrayEnd`),T(e,t,`allowClassStart`),T(e,t,`allowClassEnd`),T(e,t,`allowInterfaceStart`),T(e,t,`allowInterfaceEnd`),T(e,t,`allowTypeStart`),T(e,t,`allowTypeEnd`),T(e,t,`allowEnumStart`),T(e,t,`allowEnumEnd`),T(e,t,`allowModuleStart`),T(e,t,`allowModuleEnd`),T(e,t,`allowFunctionStart`),T(e,t,`allowFunctionEnd`),T(e,t,`applyDefaultIgnorePatterns`)}function D(e,t,n){let r=t[n];typeof r==`string`&&(e[n]=r)}function O(e){let t={...h};return w(e)&&(E(t,e),D(t,e,`ignorePattern`)),t}function k(e,t){return e<=1||t[e-2]?.trim()===``}function A(e,t){return e>=t.length||t[e]?.trim()===``}function j(e,t){return e.isBlockStart&&(t.allowBlockStart??!1)||e.isObjectStart&&(t.allowObjectStart??!1)||e.isArrayStart&&(t.allowArrayStart??!1)||e.isClassStart&&(t.allowClassStart??!1)||e.isInterfaceStart&&(t.allowInterfaceStart??!1)||e.isTypeStart&&(t.allowTypeStart??!1)||e.isEnumStart&&(t.allowEnumStart??!1)||e.isModuleStart&&(t.allowModuleStart??!1)||e.isFunctionStart&&(t.allowFunctionStart??!1)}function M(e,t){return e.isBlockEnd&&(t.allowBlockEnd??!1)||e.isObjectEnd&&(t.allowObjectEnd??!1)||e.isArrayEnd&&(t.allowArrayEnd??!1)||e.isClassEnd&&(t.allowClassEnd??!1)||e.isInterfaceEnd&&(t.allowInterfaceEnd??!1)||e.isTypeEnd&&(t.allowTypeEnd??!1)||e.isEnumEnd&&(t.allowEnumEnd??!1)||e.isModuleEnd&&(t.allowModuleEnd??!1)||e.isFunctionEnd&&(t.allowFunctionEnd??!1)}function N(e,t,n,r,i){let a=e.type===`Block`;if(a&&n.beforeBlockComment||!a&&n.beforeLineComment){if(j(i,n))return;let o=e.loc.start.line;k(o,t)||r.report({loc:{start:e.loc.start,end:e.loc.start},message:a?`块注释前需要空行`:`行注释前需要空行`,fix:n=>{let r=0;for(let n=0;n<e.loc.start.line-1;n++)r+=(t[n]?.length??0)+1;return n.insertTextBeforeRange([r,r],`
2
+ `)}})}}function P(e,t,n,r,i){let a=e.type===`Block`;if(a&&n.afterBlockComment||!a&&n.afterLineComment){if(M(i,n))return;let o=e.loc.end.line;A(o,t)||r.report({loc:{start:e.loc.end,end:e.loc.end},message:a?`块注释后需要空行`:`行注释后需要空行`,fix:t=>t.insertTextAfterRange([e.range[1],e.range[1]],`
3
+ `)})}}function F(e,t,n,r,i=[],a=!1,o=!1){if(b(e,t)||C(e,n))return;let s=x(e,i),c=m(e,t),l=ee(e,t)||te(e,t),u=re(e,t);!a&&!s&&!l&&!u&&N(e,t,n,r,c),o||P(e,t,n,r,c)}const ie=e({meta:{type:`layout`,fixable:`whitespace`,docs:{description:`要求在注释前后有空行`},schema:[{type:`object`,properties:{beforeBlockComment:{type:`boolean`},afterBlockComment:{type:`boolean`},beforeLineComment:{type:`boolean`},afterLineComment:{type:`boolean`},allowBlockStart:{type:`boolean`},allowBlockEnd:{type:`boolean`},allowObjectStart:{type:`boolean`},allowObjectEnd:{type:`boolean`},allowArrayStart:{type:`boolean`},allowArrayEnd:{type:`boolean`},allowClassStart:{type:`boolean`},allowClassEnd:{type:`boolean`},allowInterfaceStart:{type:`boolean`},allowInterfaceEnd:{type:`boolean`},allowTypeStart:{type:`boolean`},allowTypeEnd:{type:`boolean`},allowEnumStart:{type:`boolean`},allowEnumEnd:{type:`boolean`},allowModuleStart:{type:`boolean`},allowModuleEnd:{type:`boolean`},allowFunctionStart:{type:`boolean`},allowFunctionEnd:{type:`boolean`},ignorePattern:{type:`string`},applyDefaultIgnorePatterns:{type:`boolean`}},additionalProperties:!1}]},createOnce(e){let t=[],n=[];return{Program(){let r=O(e.options?.[0]);t=e.sourceCode.text.split(`
4
+ `),n=[];let i=e.sourceCode.getAllComments();for(let a=0;a<i.length;a++){let o=i[a];if(!o)continue;let s=i[a+1],c=s!==void 0&&s.loc.start.line<=o.loc.end.line+1;F(o,t,r,e,n,!1,c),n.push(o)}}}}}),I=[`eslint`,`oxlint`,`jshint`,`jslint`,`tslint`,`istanbul`,`global`,`exported`,`jscs`],L=[`<reference`,`<amd-module`,`<amd-dependency`,`@ts-`],R=/^\*?\s*$/u,z=/^\s*$/u,B=`禁止双斜杠注释,只允许多行块注释`;function V(e){let t=e.value.trim(),n=t.replace(/^\/+/u,``).trim();return I.some(e=>t.startsWith(e))||L.some(e=>n.startsWith(e))}function H(e){return e.type===`Line`&&n(e.value)!==null}function U(e,t){let n=t[e.loc.start.line-1];if(!n)return` `.repeat(e.loc.start.column);let r=n.slice(0,e.loc.start.column);return r.trim().length>0?` `.repeat(e.loc.start.column):r}function W(e){let t=[];for(let n of e){let e=t[t.length-1];if(e){let t=e[e.length-1];if(t&&t.loc.end.line===n.loc.start.line-1){e.push(n);continue}}t.push([n])}return t}function G(e){return e.map(e=>e.value)}function K(e,t){return`/*\n${e.map(e=>{let n=e.trim();return n?`${t} * ${n}`:`${t} *`}).join(`
5
+ `)}\n${t} */`}function q(e,t){let n=e.trim();return n?`/*\n${t} * ${n}\n${t} */`:`/*\n${t} */`}function J(e,t){let n=e.value.split(`
6
+ `),r=0;for(let e=0;e<t;e++)r+=(n[e]?.length??0)+1;return e.range[0]+2+r}function Y(e,t){let n=[],r=[];for(let i of e)b(i,t)?n.push({message:B,loc:{start:{...i.loc.start},end:{...i.loc.end}}}):r.push(i);for(let e of W(r)){let r=e[0],i=e[e.length-1];if(!r||!i)continue;let a=U(r,t),o=G(e),s=o.some(e=>e.trim().startsWith(`/`));n.push({message:B,loc:{start:{...r.loc.start},end:{...i.loc.end}},fix:s?void 0:{range:[r.range[0],i.range[1]],text:K(o,a)}})}return n}function ae(e,t){let n=[],r=e.value.split(`
7
+ `),i=U(e,t);if(e.loc.start.line===e.loc.end.line)return n.push({message:`禁止单行块注释,注释须为多行星号块形态`,loc:{start:{...e.loc.start},end:{...e.loc.end}},fix:{range:[e.range[0],e.range[1]],text:q(e.value,i)}}),n;let a=r[0]??``;if(!R.test(a)){let t=+!!a.startsWith(`*`);n.push({message:`多行块注释的首行应在 "/*" 后换行`,loc:{start:{...e.loc.start},end:{...e.loc.end}},fix:{range:[e.range[0]+2,e.range[0]+2+t],text:`\n${i} *`}})}for(let t=1;t<r.length-1;t++){let a=r[t]??``,o=a.trim();if(!o||o.startsWith(`*`))continue;let s=J(e,t),c=a.length-a.trimStart().length;n.push({message:`多行注释的中间行应以 "*" 开头`,loc:{start:{line:e.loc.start.line+t,column:0},end:{line:e.loc.start.line+t,column:a.length}},fix:{range:[s,s+c],text:`${i} * `}})}let o=r[r.length-1]??``;return z.test(o)||n.push({message:`多行块注释的末行应在 "*/" 前换行`,loc:{start:{...e.loc.start},end:{...e.loc.end}},fix:{range:[e.range[1]-2,e.range[1]-2],text:`\n${i} `}}),n}function oe(e,t){let n=[],r=[];for(let i of e)i.type!==`Shebang`&&(V(i)||H(i)||(i.type===`Line`?r.push(i):n.push(...ae(i,t))));return n.push(...Y(r,t)),n}const se=e({meta:{type:`layout`,fixable:`code`,docs:{description:`强制多行注释使用星号块样式`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments(),r=e.sourceCode.text,i=oe(n,r==null?[]:r.split(`
8
+ `));for(let t of i){let{fix:n}=t;e.report({loc:t.loc,message:t.message,fix:n?e=>e.replaceTextRange(n.range,n.text):void 0})}}}}});function X(e){return e.type===`ExportNamedDeclaration`||e.type===`ExportDefaultDeclaration`||e.type===`ExportAllDeclaration`}function ce(e,t,n){if(n-t<=1)return!1;for(let r=t+1;r<n;r++)if(e[r-1]?.trim()===``)return!0;return!1}function Z(e){return e.type===`Program`}function le(e,t,n){for(let r=1;r<e.length;r++){let i=e[r-1],a=e[r];if(i!==void 0&&a!==void 0&&X(i)&&X(a)){let e=i.loc.end.line,r=a.loc.start.line;ce(t,e,r)||n.report({loc:a.loc.start,message:`export 语句之间需要空行`})}}}const Q={"multiline-comment-style":se,"lines-around-comment":ie,"padding-line-between-statements":e({meta:{type:`layout`,docs:{description:`要求在 export 语句之间有空行`}},createOnce(e){return{Program(t){let n=e.sourceCode.text.split(`
9
+ `),r=Z(t)?t:null;r&&le(r.body,n,e)}}}})},$=t({meta:{name:`@longzai-intelligence-oxlint/stylistic-plugin`},rules:Q});export{$ as default,$ as stylisticPlugin,Q as stylisticRules};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-oxlint/stylistic-plugin",
3
- "version": "0.1.36",
3
+ "version": "0.1.38",
4
4
  "description": "Longzai Intelligence oxlint stylistic 风格规则插件",
5
5
  "keywords": [
6
6
  "formatting",
@@ -44,8 +44,8 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@longzai-intelligence-logger/node": "^0.1.1",
47
- "@longzai-intelligence-oxlint/core": "0.1.36",
48
- "@longzai-intelligence-oxlint/tsdoc-plugin": "0.1.36",
47
+ "@longzai-intelligence-oxlint/core": "0.1.38",
48
+ "@longzai-intelligence-oxlint/tsdoc-plugin": "0.1.38",
49
49
  "@oxlint/plugins": "^1.74.0"
50
50
  },
51
51
  "devDependencies": {