Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
horuskol committed Oct 25, 2020
1 parent af25fcf commit 836190a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Additionally, the plugin will create properly indexed utilities for line names d
module.exports = {
theme: {
gridTemplateColumns: {
'default-layout': 'repeat(3, [left] 1fr [right]',
'default-layout': 'repeat(3, [left] 1fr [right])',
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@savvywombat/tailwindcss-grid-named-lines",
"version": "1.2.0",
"version": "1.2.1",
"description": "A plugin to provide TailwindCSS utilities for named grid lines.",
"keywords": [
"tailwind",
Expand Down
11 changes: 7 additions & 4 deletions src/util/extractGridLineNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ module.exports = function (gridTemplate) {
}),
// extract repeat(n, def)
..._.flatMap(value.match(/repeat\([^\)]*\)/g), (repeat) => {
const found = repeat.match(/\((?<count>[0-9]+),\s*(\[(?<first>[^\]]+)\])?[^\[]+(\[(?<second>[^\]]+)\])?/)
const found = repeat.match(
/\((?<count>[0-9]+),\s*(\[(?<first>[^\]]+)\])?[^\[]+(\[(?<second>[^\]]+)\])?/
)

if (typeof found.groups.count === 'undefined') {
return []
}

let result = [];
let result = []
// start at 1 here reduce the number of repeated names by one
// because the first match above will include the names from repeat(n, def)
for (let i = 1; i < found.groups.count; i++) {
Expand All @@ -33,10 +35,11 @@ module.exports = function (gridTemplate) {
}

return result
})
}),
]
// create a unique list of names, including counts of how many times that name is used
const counts = _.fromPairs(matches
const counts = _.fromPairs(
matches
.filter((v, i, a) => a.indexOf(v) === i)
.map((match) => {
return [
Expand Down
16 changes: 13 additions & 3 deletions test/util/extractGridLineNames.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ test('multiple gridTemplates can use the same grid line names', () => {
four: '[column] 1fr [column] 1fr [column]',
}

expect(extractGridLineNames(gridTemplateRows)).toEqual(['left', 'right', 'column 1', 'column 2', 'column 3'])
expect(extractGridLineNames(gridTemplateRows)).toEqual([
'left',
'right',
'column 1',
'column 2',
'column 3',
])
})

test('supports repeat', () => {
Expand All @@ -76,13 +82,17 @@ test('includes start and end from repeat', () => {
layout: 'repeat(2, [instart] 1fr [inend])',
}

expect(extractGridLineNames(gridTemplateRows)).toEqual(expect.arrayContaining(['instart 1', 'instart 2', 'inend 1', 'inend 2']))
expect(extractGridLineNames(gridTemplateRows)).toEqual(
expect.arrayContaining(['instart 1', 'instart 2', 'inend 1', 'inend 2'])
)
})

test('supports multiple repeats', () => {
const gridTemplateRows = {
layout: 'repeat(2, [line] 1fr) repeat(2, [more] 2fr)',
}

expect(extractGridLineNames(gridTemplateRows)).toEqual(expect.arrayContaining(['line 1', 'line 2', 'more 1', 'more 2']))
expect(extractGridLineNames(gridTemplateRows)).toEqual(
expect.arrayContaining(['line 1', 'line 2', 'more 1', 'more 2'])
)
})

0 comments on commit 836190a

Please sign in to comment.