Skip to content

Commit

Permalink
Update ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Oct 26, 2023
1 parent 11a1c80 commit 07bc511
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 187 deletions.
3 changes: 1 addition & 2 deletions examples/eslint/collision.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- eslint-disable @master/css/class-order -->
<div class="m:10 m:40 m:50 m:60 m:20 m:40@sm m:60@sm m:30:hover m:40@dark">
<div class="m:10 m:20 m:30 m:40@sm m:50@sm">
...
</div>

2 changes: 1 addition & 1 deletion packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@types/node": "^20.6.0",
"@typescript-eslint/parser": "^5.50.0",
"@typescript-eslint/utils": "^6.9.0",
"eslint": "^7.1.0",
"eslint": "^8.0.0",
"svelte-eslint-parser": "^0.33.1",
"vue-eslint-parser": "^9.3.1"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin/src/rules/class-collision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
node,
arg,
(classNames, node, originalClassNamesValue, start, end) => {
const sourceCode = context.getSourceCode()
const sourceCode = context.sourceCode
const sourceCodeLines = sourceCode.lines
const nodeStartLine = node.loc.start.line
const nodeEndLine = node.loc.end.line
Expand Down Expand Up @@ -56,7 +56,7 @@ export default {
}

if (conflicts.length > 0) {
const conflictClassNamesMsg = conflicts.map(x => `\`${x}\``).join(' and ')
const conflictClassNamesMsg = conflicts.map(x => `"${x}"`).join(' and ')
let fixClassNames = originalClassNamesValue
for (const conflictClassName of conflicts) {
const regexSafe = conflictClassName.replace(/(\\|\.|\(|\)|\[|\]|\{|\}|\+|\*|\?|\^|\$|\||\/)/g, '\\$1')
Expand All @@ -66,7 +66,7 @@ export default {
loc: astUtil.findLoc(className, sourceCodeLines, nodeStartLine, nodeEndLine),
messageId: 'collisionClass',
data: {
message: `\`${className}\` applies the same CSS declarations as ${conflictClassNamesMsg}.
message: `"${className}" applies the same CSS declarations as ${conflictClassNamesMsg}.
`,
},
fix: function (fixer) {
Expand Down
8 changes: 5 additions & 3 deletions packages/eslint-plugin/src/rules/class-order.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-case-declarations */
import * as astUtil from '../utils/ast'
import defineVisitors from '../utils/define-visitors'
import resolveContext from '../utils/resolve-context'
Expand Down Expand Up @@ -94,15 +95,16 @@ export default {
// The problem is that range computation includes the backticks (`test`)
// but value.raw does not include them, so there is a mismatch.
// start/end does not include the backticks, therefore it matches value.raw.
const txt = context.getSourceCode().getText(arg)
const txt = context.sourceCode.getText(arg)

prefix = astUtil.getTemplateElementPrefix(txt, originalClassNamesValue)
suffix = astUtil.getTemplateElementSuffix(txt, originalClassNamesValue)
originalClassNamesValue = astUtil.getTemplateElementBody(txt, prefix, suffix)
break
}
}

let { classNames, whitespaces, headSpace, tailSpace } =
const { classNames, whitespaces, headSpace, tailSpace } =
astUtil.extractClassnamesFromValue(originalClassNamesValue)

if (classNames.length <= 1) {
Expand Down Expand Up @@ -135,7 +137,7 @@ export default {

if (originalClassNamesValue !== validatedClassNamesValue) {
validatedClassNamesValue = prefix + validatedClassNamesValue + suffix
const sourceCode = context.getSourceCode()
const sourceCode = context.sourceCode
const sourceCodeLines = sourceCode.lines
const nodeStartLine = node.loc.start.line
const nodeEndLine = node.loc.end.line
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/class-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
node,
arg,
(classNames, node) => {
const sourceCode = context.getSourceCode()
const sourceCode = context.sourceCode
const sourceCodeLines = sourceCode.lines
const nodeStartLine = node.loc.start.line
const nodeEndLine = node.loc.end.line
Expand Down
Loading

0 comments on commit 07bc511

Please sign in to comment.