Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions eslint-local-rules/__tests__/lint-markdown-code-blocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ const path = require('path');
const {ESLint} = require('eslint');
const plugin = require('..');

const FIXTURES_DIR = path.join(
__dirname,
'fixtures',
'src',
'content'
);
const FIXTURES_DIR = path.join(__dirname, 'fixtures', 'src', 'content');
const PARSER_PATH = path.join(__dirname, '..', 'parser.js');

function createESLint({fix = false} = {}) {
Expand Down Expand Up @@ -53,11 +48,7 @@ async function lintFixture(name, {fix = false} = {}) {

async function run() {
const basicResult = await lintFixture('basic-error.md');
assert.strictEqual(
basicResult.messages.length,
1,
'expected one diagnostic'
);
assert.strictEqual(basicResult.messages.length, 1, 'expected one diagnostic');
assert(
basicResult.messages[0].message.includes('Calling setState during render'),
'expected message to mention setState during render'
Expand Down Expand Up @@ -91,9 +82,7 @@ async function run() {
fix: true,
});
assert(
duplicateFixed.output.includes(
"{expectedErrors: {'react-compiler': [4]}}"
),
duplicateFixed.output.includes("{expectedErrors: {'react-compiler': [4]}}"),
'expected duplicates to be rewritten to a single canonical block'
);
assert(
Expand All @@ -118,14 +107,12 @@ async function run() {
fix: true,
});
assert(
malformedFixed.output.includes(
"{expectedErrors: {'react-compiler': [4]}}"
),
malformedFixed.output.includes("{expectedErrors: {'react-compiler': [4]}}"),
'expected malformed metadata to be replaced with canonical form'
);
}

run().catch(error => {
run().catch((error) => {
console.error(error);
process.exitCode = 1;
});
12 changes: 9 additions & 3 deletions eslint-local-rules/rules/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,19 @@ function parseExpectedErrorsEntries(rawEntries) {

if (parsed && typeof parsed === 'object') {
for (const [key, value] of Object.entries(parsed)) {
entries[key] = normalizeEntryValues(Array.isArray(value) ? value.flat() : value);
entries[key] = normalizeEntryValues(
Array.isArray(value) ? value.flat() : value
);
}
}

return entries;
}

function parseExpectedErrorsToken(tokenText) {
const match = tokenText.match(/^\{\s*expectedErrors\s*:\s*(\{[\s\S]*\})\s*\}$/);
const match = tokenText.match(
/^\{\s*expectedErrors\s*:\s*(\{[\s\S]*\})\s*\}$/
);
if (!match) {
return null;
}
Expand Down Expand Up @@ -203,7 +207,9 @@ function cloneMetadata(metadata) {
}

function findExpectedErrorsToken(metadata) {
return metadata.tokens.find((token) => token.type === 'expectedErrors') || null;
return (
metadata.tokens.find((token) => token.type === 'expectedErrors') || null
);
}

function getCompilerExpectedLines(metadata) {
Expand Down
14 changes: 8 additions & 6 deletions eslint-local-rules/rules/react-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,19 @@ function runReactCompiler(code, filename) {
continue;
}

const loc = typeof detail.primaryLocation === 'function'
? detail.primaryLocation()
: null;
const loc =
typeof detail.primaryLocation === 'function'
? detail.primaryLocation()
: null;

if (loc == null || typeof loc === 'symbol') {
continue;
}

const message = typeof detail.printErrorMessage === 'function'
? detail.printErrorMessage(result.sourceCode, {eslint: true})
: detail.description || 'Unknown React Compiler error';
const message =
typeof detail.printErrorMessage === 'function'
? detail.printErrorMessage(result.sourceCode, {eslint: true})
: detail.description || 'Unknown React Compiler error';

diagnostics.push({detail, loc, message});
}
Expand Down
Loading