Skip to content

Commit

Permalink
chore: fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh committed Aug 8, 2024
1 parent 68dcb15 commit 1f2b7de
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
3 changes: 1 addition & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { builtinModules } from 'node:module';

import tseslint from 'typescript-eslint';

Expand Down Expand Up @@ -28,7 +27,7 @@ export default [
languageOptions: {
parser: typescriptParser,
parserOptions: {
project: ['./tsconfig.json'],
project: ['./tsconfig.eslint.json'],
tsconfigRootDir: __dirname,
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface PluginOptions {
}

declare module 'prettier' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface RequiredOptions extends PluginOptions {}
}

Expand Down
4 changes: 2 additions & 2 deletions src/printer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export function print(path: AstPath, opts: ParserOptions, print: printFn): Doc {

if (isEmptyTextNode(node)) {
const hasWhiteSpace = rawText.trim().length < getUnencodedText(node).length;
const hasOneOrMoreNewlines = /\n/.test(getUnencodedText(node));
const hasTwoOrMoreNewlines = /\n\r?\s*\n\r?/.test(getUnencodedText(node));
const hasOneOrMoreNewlines = getUnencodedText(node).includes('\n');
const hasTwoOrMoreNewlines = /\n\s*\n\r?/.test(getUnencodedText(node));
if (hasTwoOrMoreNewlines) {
return [hardline, hardline];
}
Expand Down
10 changes: 5 additions & 5 deletions src/printer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export function trimTextNodeRight(node: TextNode): void {
export function printClassNames(value: string) {
const lines = value.trim().split(/[\r\n]+/);
const formattedLines = lines.map((line) => {
const spaces = line.match(/^\s+/);
const spaces = /^\s+/.exec(line);
return (spaces ? spaces[0] : '') + line.trim().split(/\s+/).join(' ');
});
return formattedLines.join('\n');
Expand All @@ -216,11 +216,11 @@ export function manualDedent(input: string): {
for (const line of result.split('\n')) {
if (!line) continue;
// if any line begins with a non-whitespace char, minTabSize is 0
if (line[0] && /^[^\s]/.test(line[0])) {
if (line[0] && /^\S/.test(line[0])) {
minTabSize = 0;
break;
}
const match = line.match(/^(\s+)\S+/); // \S ensures we don’t count lines of pure whitespace
const match = /^(\s+)\S+/.exec(line); // \S ensures we don’t count lines of pure whitespace
if (match) {
if (match[1] && !char) char = match[1][0];
if (match[1].length < minTabSize) minTabSize = match[1].length;
Expand Down Expand Up @@ -315,8 +315,8 @@ export function getPreferredQuote(rawContent: string, preferredQuote: string): Q
// the string, we might want to enclose with the alternate quote instead, to
// minimize the number of escaped quotes.
if (rawContent.includes(preferred.quote) || rawContent.includes(alternate.quote)) {
const numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
const numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
const numPreferredQuotes = (preferred.regex.exec(rawContent) || []).length;
const numAlternateQuotes = (alternate.regex.exec(rawContent) || []).length;

result = numPreferredQuotes > numAlternateQuotes ? alternate : preferred;
}
Expand Down
6 changes: 3 additions & 3 deletions test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ function getFiles(file: any, path: string, isMarkdown = false) {
let input: string = file[`/test/fixtures/${path}/input.${ext}`];
let output: string = file[`/test/fixtures/${path}/output.${ext}`];
// workaround: normalize end of lines to pass windows ci
if (input) input = input.replace(/(\r\n|\r)/gm, '\n');
if (output) output = output.replace(/(\r\n|\r)/gm, '\n');
if (input) input = input.replace(/\r\n|\r/g, '\n');
if (output) output = output.replace(/\r\n|\r/g, '\n');
return { input, output };
}

Expand All @@ -63,7 +63,7 @@ function getOptions(files: any, path: string) {
let opts: object;
try {
opts = JSON.parse(files[`/test/fixtures/${path}/options.json`]);
} catch (e) {
} catch {
opts = {};
}
return opts;
Expand Down
7 changes: 7 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"checkJs": true
},
"include": ["src/**/*.ts", "test/**/*.ts", "*"]
}

0 comments on commit 1f2b7de

Please sign in to comment.