Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
Renovate Bot
renovate
Commits
2fe8305a
Unverified
Commit
2fe8305a
authored
4 months ago
by
Janus Troelsen
Committed by
GitHub
4 months ago
Browse files
Options
Downloads
Patches
Plain Diff
fix(manager/haskell-cabal): Handle comments in Cabal file (#33695)
parent
9d818ffb
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/modules/manager/haskell-cabal/extract.spec.ts
+19
-0
19 additions, 0 deletions
lib/modules/manager/haskell-cabal/extract.spec.ts
lib/modules/manager/haskell-cabal/extract.ts
+20
-4
20 additions, 4 deletions
lib/modules/manager/haskell-cabal/extract.ts
with
39 additions
and
4 deletions
lib/modules/manager/haskell-cabal/extract.spec.ts
+
19
−
0
View file @
2fe8305a
...
@@ -2,10 +2,19 @@ import {
...
@@ -2,10 +2,19 @@ import {
countPackageNameLength
,
countPackageNameLength
,
countPrecedingIndentation
,
countPrecedingIndentation
,
extractNamesAndRanges
,
extractNamesAndRanges
,
findDepends
,
findExtents
,
findExtents
,
splitSingleDependency
,
splitSingleDependency
,
}
from
'
./extract
'
;
}
from
'
./extract
'
;
const
commentCabalFile
=
`build-depends:
-- leading
base,
-- middle
other,
-- trailing
other2`
;
describe
(
'
modules/manager/haskell-cabal/extract
'
,
()
=>
{
describe
(
'
modules/manager/haskell-cabal/extract
'
,
()
=>
{
describe
(
'
countPackageNameLength
'
,
()
=>
{
describe
(
'
countPackageNameLength
'
,
()
=>
{
it
.
each
`
it
.
each
`
...
@@ -91,4 +100,14 @@ describe('modules/manager/haskell-cabal/extract', () => {
...
@@ -91,4 +100,14 @@ describe('modules/manager/haskell-cabal/extract', () => {
]);
]);
});
});
});
});
describe
(
'
findDepends()
'
,
()
=>
{
it
(
'
strips comments
'
,
()
=>
{
const
res
=
findDepends
(
commentCabalFile
+
'
\n
a: b
'
);
expect
(
res
).
toEqual
({
buildDependsContent
:
'
\n
base,
\n
other,
\n
other2
'
,
lengthProcessed
:
commentCabalFile
.
length
,
});
});
});
});
});
This diff is collapsed.
Click to expand it.
lib/modules/manager/haskell-cabal/extract.ts
+
20
−
4
View file @
2fe8305a
...
@@ -3,6 +3,7 @@ import { regEx } from '../../../util/regex';
...
@@ -3,6 +3,7 @@ import { regEx } from '../../../util/regex';
const
buildDependsRegex
=
regEx
(
const
buildDependsRegex
=
regEx
(
/
(?<
buildDependsFieldName>build-depends
[
\t]
*:
)
/i
,
/
(?<
buildDependsFieldName>build-depends
[
\t]
*:
)
/i
,
);
);
const
commentRegex
=
regEx
(
/^
[
\t]
*--/
);
function
isNonASCII
(
str
:
string
):
boolean
{
function
isNonASCII
(
str
:
string
):
boolean
{
for
(
let
i
=
0
;
i
<
str
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
str
.
length
;
i
++
)
{
if
(
str
.
charCodeAt
(
i
)
>
127
)
{
if
(
str
.
charCodeAt
(
i
)
>
127
)
{
...
@@ -86,6 +87,11 @@ export function findExtents(indent: number, content: string): number {
...
@@ -86,6 +87,11 @@ export function findExtents(indent: number, content: string): number {
break
;
break
;
}
}
if
(
thisIndent
<
indent
)
{
if
(
thisIndent
<
indent
)
{
if
(
content
.
slice
(
blockIdx
-
1
,
blockIdx
+
1
)
===
'
--
'
)
{
// not enough indention, but the line is a comment, so include it
mode
=
'
finding-newline
'
;
continue
;
}
// go back to before the newline
// go back to before the newline
for
(;;)
{
for
(;;)
{
if
(
content
[
blockIdx
--
]
===
'
\n
'
)
{
if
(
content
[
blockIdx
--
]
===
'
\n
'
)
{
...
@@ -125,7 +131,8 @@ export function countPrecedingIndentation(
...
@@ -125,7 +131,8 @@ export function countPrecedingIndentation(
*
*
* @returns {{buildDependsContent: string, lengthProcessed: number}}
* @returns {{buildDependsContent: string, lengthProcessed: number}}
* buildDependsContent:
* buildDependsContent:
* the contents of the field, excluding the field name and the colon.
* the contents of the field, excluding the field name and the colon,
* and any comments within
*
*
* lengthProcessed:
* lengthProcessed:
* points to after the end of the field. Note that the field does _not_
* points to after the end of the field. Note that the field does _not_
...
@@ -143,10 +150,19 @@ export function findDepends(
...
@@ -143,10 +150,19 @@ export function findDepends(
const
indent
=
countPrecedingIndentation
(
content
,
matchObj
.
index
);
const
indent
=
countPrecedingIndentation
(
content
,
matchObj
.
index
);
const
ourIdx
:
number
=
const
ourIdx
:
number
=
matchObj
.
index
+
matchObj
.
groups
[
'
buildDependsFieldName
'
].
length
;
matchObj
.
index
+
matchObj
.
groups
[
'
buildDependsFieldName
'
].
length
;
const
extent
:
number
=
findExtents
(
indent
+
1
,
content
.
slice
(
ourIdx
));
const
extentLength
:
number
=
findExtents
(
indent
+
1
,
content
.
slice
(
ourIdx
));
const
extent
=
content
.
slice
(
ourIdx
,
ourIdx
+
extentLength
);
const
lines
=
[];
// Windows-style line breaks are fine because
// carriage returns are before the line feed.
for
(
const
maybeCommentLine
of
extent
.
split
(
'
\n
'
))
{
if
(
!
commentRegex
.
test
(
maybeCommentLine
))
{
lines
.
push
(
maybeCommentLine
);
}
}
return
{
return
{
buildDependsContent
:
content
.
slice
(
ourIdx
,
ourIdx
+
extent
),
buildDependsContent
:
lines
.
join
(
'
\n
'
),
lengthProcessed
:
ourIdx
+
extent
,
lengthProcessed
:
ourIdx
+
extent
Length
,
};
};
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment