Skip to content

Commit

Permalink
Add trailing commas; lint on CI (#553)
Browse files Browse the repository at this point in the history
* Fix ci to actually lint

* Add trailing commas
  • Loading branch information
RyanZim committed Jan 3, 2024
1 parent 97690de commit 7fb74a5
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Expand Up @@ -18,4 +18,4 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
- run: npm run ci
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -55,7 +55,7 @@ function AtImport(options) {
state,
[],
[],
postcss
postcss,
)

applyRaws(bundle)
Expand Down
2 changes: 1 addition & 1 deletion lib/apply-conditions.js
Expand Up @@ -15,7 +15,7 @@ module.exports = function applyConditions(bundle, atRule) {
if (stmt.type === "import") {
stmt.node.params = base64EncodedConditionalImport(
stmt.fullUri,
stmt.conditions
stmt.conditions,
)
return
}
Expand Down
6 changes: 3 additions & 3 deletions lib/base64-encoded-import.js
Expand Up @@ -13,16 +13,16 @@ module.exports = function base64EncodedConditionalImport(prelude, conditions) {
let params = `${prelude} ${formatImportPrelude(
first.layer,
first.media,
first.supports
first.supports,
)}`

for (const condition of conditions) {
params = `'data:text/css;base64,${Buffer.from(`@import ${params}`).toString(
"base64"
"base64",
)}' ${formatImportPrelude(
condition.layer,
condition.media,
condition.supports
condition.supports,
)}`
}

Expand Down
8 changes: 4 additions & 4 deletions lib/parse-statements.js
Expand Up @@ -106,7 +106,7 @@ function parseImport(result, atRule, conditions, from) {

return result.warn(
"@import must precede all other statements (besides @charset or empty @layer)",
{ node: atRule }
{ node: atRule },
)
} while (prev)
}
Expand All @@ -115,7 +115,7 @@ function parseImport(result, atRule, conditions, from) {
return result.warn(
"It looks like you didn't end your @import statement correctly. " +
"Child nodes are attached to it.",
{ node: atRule }
{ node: atRule },
)
}

Expand Down Expand Up @@ -195,7 +195,7 @@ function parseImport(result, atRule, conditions, from) {
`layers must be defined before support conditions in '${atRule.toString()}'`,
{
node: atRule,
}
},
)
}

Expand All @@ -214,7 +214,7 @@ function parseImport(result, atRule, conditions, from) {
`Multiple support conditions in '${atRule.toString()}'`,
{
node: atRule,
}
},
)
}

Expand Down
20 changes: 10 additions & 10 deletions lib/parse-styles.js
Expand Up @@ -15,7 +15,7 @@ async function parseStyles(
state,
conditions,
from,
postcss
postcss,
) {
const statements = parseStatements(result, styles, conditions, from)

Expand Down Expand Up @@ -45,7 +45,7 @@ async function parseStyles(
throw stmt.node.error(
`Incompatible @charset statements:
${stmt.node.params} specified in ${stmt.node.source.input.file}
${charset.node.params} specified in ${charset.node.source.input.file}`
${charset.node.params} specified in ${charset.node.source.input.file}`,
)
}
}
Expand Down Expand Up @@ -80,14 +80,14 @@ async function resolveImportId(result, stmt, options, state, postcss) {
stmt.uri,
options,
state,
postcss
postcss,
)

return
} else if (dataURL.isValid(stmt.from.slice(-1))) {
// Data urls can't be used as a base url to resolve imports.
throw stmt.node.error(
`Unable to import '${stmt.uri}' from a stylesheet that is embedded in a data url`
`Unable to import '${stmt.uri}' from a stylesheet that is embedded in a data url`,
)
}

Expand All @@ -108,7 +108,7 @@ async function resolveImportId(result, stmt, options, state, postcss) {
return !path.isAbsolute(file)
? resolveId(file, base, options, atRule)
: file
})
}),
)

// Add dependency messages:
Expand All @@ -124,7 +124,7 @@ async function resolveImportId(result, stmt, options, state, postcss) {
const importedContent = await Promise.all(
resolved.map(file => {
return loadImportContent(result, stmt, file, options, state, postcss)
})
}),
)

// Merge loaded statements
Expand All @@ -138,13 +138,13 @@ async function loadImportContent(
filename,
options,
state,
postcss
postcss,
) {
const atRule = stmt.node
const { conditions, from } = stmt
const stmtDuplicateCheckKey = conditions
.map(condition =>
formatImportPrelude(condition.layer, condition.media, condition.supports)
formatImportPrelude(condition.layer, condition.media, condition.supports),
)
.join(":")

Expand Down Expand Up @@ -185,7 +185,7 @@ async function loadImportContent(
content,
filename,
options,
postcss
postcss,
)

const styles = importedResult.root
Expand Down Expand Up @@ -213,7 +213,7 @@ async function loadImportContent(
state,
conditions,
[...from, filename],
postcss
postcss,
)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/process-content.js
Expand Up @@ -11,7 +11,7 @@ module.exports = function processContent(
content,
filename,
options,
postcss
postcss,
) {
const { plugins } = options
const ext = path.extname(filename)
Expand Down
2 changes: 1 addition & 1 deletion lib/resolve-id.js
Expand Up @@ -36,7 +36,7 @@ module.exports = function resolveId(id, base, options, node) {
`Failed to find '${id}'
in [
${paths.join(",\n ")}
]`
]`,
)
})
}
10 changes: 5 additions & 5 deletions test/custom-resolve.js
Expand Up @@ -23,10 +23,10 @@ test.serial(
{
resolve: () => {
return Promise.resolve(
path.resolve("test/fixtures/imports/custom-resolve-1.css")
path.resolve("test/fixtures/imports/custom-resolve-1.css"),
)
},
}
},
)

test.serial(
Expand All @@ -41,7 +41,7 @@ test.serial(
path.resolve("test/fixtures/imports/custom-resolve-1.css"),
]
},
}
},
)

test.serial(
Expand All @@ -56,7 +56,7 @@ test.serial(
path.resolve("test/fixtures/imports/custom-resolve-1.css"),
])
},
}
},
)

test("should apply default resolver when custom doesn't return an absolute path", t => {
Expand All @@ -68,7 +68,7 @@ test("should apply default resolver when custom doesn't return an absolute path"
t.is(p, path.resolve("test/fixtures/imports", "bar.css"))
return "/* comment */"
},
})
}),
)
.process(`@import "foo.css";`, {
from: "test/fixtures/custom-resolve-file",
Expand Down
10 changes: 5 additions & 5 deletions test/custom-syntax-parser.js
Expand Up @@ -16,7 +16,7 @@ test(
checkFixture,
"scss-parser",
null,
{ parser: scss }
{ parser: scss },
)

test(".css importing .sss should work", checkFixture, "import-sss")
Expand All @@ -26,27 +26,27 @@ test(
checkFixture,
{ name: "sugar", ext: ".sss" },
null,
{ parser: sugarss }
{ parser: sugarss },
)

test(
".sss importing .css should work",
checkFixture,
{ name: "sugar-import-css", ext: ".sss" },
null,
{ parser: sugarss }
{ parser: sugarss },
)

test(
".css importing .sss importing .css should work",
checkFixture,
"import-sss-css"
"import-sss-css",
)

test(
".sss importing .css importing .sss should work",
checkFixture,
{ name: "import-css-sss", ext: ".sss" },
null,
{ parser: sugarss }
{ parser: sugarss },
)
6 changes: 3 additions & 3 deletions test/data-url.js
Expand Up @@ -16,12 +16,12 @@ test("should error on relative urls from stylesheets in data urls", t => {
.use(atImport())
.process(
"@import url(data:text/css;base64,QGltcG9ydCB1cmwoZm9vLmNzcyk7CgpwIHsKICBjb2xvcjogYmx1ZTsKfQo=);",
{ from: undefined }
{ from: undefined },
)
.catch(error =>
t.regex(
error.message,
/Unable to import '(?:.*?)' from a stylesheet that is embedded in a data url/
)
/Unable to import '(?:.*?)' from a stylesheet that is embedded in a data url/,
),
)
})
4 changes: 2 additions & 2 deletions test/helpers/check-fixture.js
Expand Up @@ -36,7 +36,7 @@ module.exports = function (t, file, opts, postcssOpts, warnings) {
t.is(
warning.text,
warnings[index],
`unexpected warning: "${warning.text}"`
`unexpected warning: "${warning.text}"`,
)
})

Expand All @@ -45,7 +45,7 @@ module.exports = function (t, file, opts, postcssOpts, warnings) {
result.warnings().length,
`expected ${warnings.length} warning(s), got ${
result.warnings().length
}`
}`,
)
})
}
2 changes: 1 addition & 1 deletion test/import-events.js
Expand Up @@ -18,7 +18,7 @@ test("should add dependency message for each import", t => {
})
.then(result => {
const deps = result.messages.filter(
message => message.type === "dependency"
message => message.type === "dependency",
)
const expected = [
{
Expand Down
20 changes: 10 additions & 10 deletions test/import.js
Expand Up @@ -23,7 +23,7 @@ test(
"duplicates",
{
skipDuplicates: false,
}
},
)

test(
Expand All @@ -32,7 +32,7 @@ test(
"cyclical",
{
skipDuplicates: false,
}
},
)

test(
Expand All @@ -41,7 +41,7 @@ test(
"cyclical-skip-duplicates",
{
skipDuplicates: true,
}
},
)

test("should import stylesheets with same content", checkFixture, "same")
Expand All @@ -64,7 +64,7 @@ test("should not fail with absolute and local import", t => {
.use(atImport())
.process(
"@import url('http://');\n@import 'test/fixtures/imports/foo.css';",
{ from: undefined }
{ from: undefined },
)
.then(result => t.is(result.css, "@import url('http://');\nfoo{}"))
})
Expand All @@ -83,7 +83,7 @@ test("should keep @charset first", t => {
test(
"should handle multiple @charset statements",
checkFixture,
"charset-import"
"charset-import",
)

test("should error if incompatible @charset statements", t => {
Expand All @@ -96,7 +96,7 @@ test("should error if incompatible @charset statements", t => {
t.truthy(err)
t.regex(
err.message,
/Incompatible @charset statements:.+specified in.+specified in.+/s
/Incompatible @charset statements:.+specified in.+specified in.+/s,
)
})
})
Expand Down Expand Up @@ -125,8 +125,8 @@ test("should contain a correct sourcemap", t => {
process.platform === "win32"
? "test/sourcemap/out.css.win.map"
: "test/sourcemap/out.css.map",
"utf8"
).trim()
"utf8",
).trim(),
)
})
})
Expand All @@ -150,14 +150,14 @@ test(
"empty-and-useless",
{ path: "test/fixtures/imports" },
null,
[`${path.resolve("test/fixtures/imports/empty.css")} is empty`]
[`${path.resolve("test/fixtures/imports/empty.css")} is empty`],
)

test(
"should be able to disable warnings for empty files",
checkFixture,
"empty-and-useless",
{ path: "test/fixtures/imports", warnOnEmpty: false }
{ path: "test/fixtures/imports", warnOnEmpty: false },
)

test("should work with no styles without throwing an error", t => {
Expand Down

0 comments on commit 7fb74a5

Please sign in to comment.