@@ -14,8 +14,13 @@ const leftBrackets = brackets.map((bracket) => {
1414const rightBrackets = brackets . map ( ( bracket ) => {
1515 return new RegExp ( bracket + "([ ])" , "g" ) ;
1616} ) ;
17- function reporter ( context ) {
17+ const defaultOptions = {
18+ allowOutsideHalfParentheses : true
19+ } ;
20+ function reporter ( context , options ) {
1821 let { Syntax, RuleError, report, fixer, getSource } = context ;
22+ const allowOutsideHalfParentheses =
23+ options . allowOutsideHalfParentheses ?? defaultOptions . allowOutsideHalfParentheses ;
1924 return {
2025 [ Syntax . Str ] ( node ) {
2126 if ( ! isUserWrittenNode ( node , context ) ) {
@@ -26,6 +31,9 @@ function reporter(context) {
2631 leftBrackets . forEach ( ( pattern ) => {
2732 matchCaptureGroupAll ( text , pattern ) . forEach ( ( match ) => {
2833 const { index } = match ;
34+ if ( allowOutsideHalfParentheses && text . substring ( index , index + 2 ) === " (" ) {
35+ return ;
36+ }
2937 report (
3038 node ,
3139 new RuleError ( "かっこの外側、内側ともにスペースを入れません。" , {
@@ -38,7 +46,10 @@ function reporter(context) {
3846 // 右にスペース
3947 rightBrackets . forEach ( ( pattern ) => {
4048 matchCaptureGroupAll ( text , pattern ) . forEach ( ( match ) => {
41- const { index, text } = match ;
49+ const { index } = match ;
50+ if ( allowOutsideHalfParentheses && text . substring ( index - 1 , index + 1 ) === ") " ) {
51+ return ;
52+ }
4253 report (
4354 node ,
4455 new RuleError ( "かっこの外側、内側ともにスペースを入れません。" , {
0 commit comments