Skip to content

Match indent #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
53 changes: 33 additions & 20 deletions bin/readmeAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ const formatCodeSnippet = (setup: Setup) => {
}

if (setup.output) {
paragraphs.push('// Fixed code: \n// ' + setup.output.split('\n').join('\n// '));
paragraphs.push(
'// Fixed code: \n// ' + setup.output.split('\n').join('\n// '),
);
}

return paragraphs.join('\n');
};

const getAssertions = () => {
const assertionFiles = glob.sync(path.resolve(__dirname, '../test/rules/assertions/*.ts'));
const assertionFiles = glob.sync(
path.resolve(__dirname, '../test/rules/assertions/*.ts'),
);

const assertionNames = _.map(assertionFiles, (filePath) => {
return path.basename(filePath, '.ts');
Expand All @@ -67,31 +71,40 @@ const updateDocuments = (assertions) => {

let documentBody = fs.readFileSync(readmeDocumentPath, 'utf8');

documentBody = documentBody.replace(/<!-- assertions ([a-z]+?) -->/giu, (assertionsBlock) => {
let exampleBody = '';
documentBody = documentBody.replace(
/<!-- assertions ([a-z]+?) -->/giu,
(assertionsBlock) => {
let exampleBody = '';

const ruleName = /assertions ([a-z]+)/iu.exec(assertionsBlock)?.[1];
const ruleName = /assertions ([a-z]+)/iu.exec(assertionsBlock)?.[1];

if (!ruleName) {
throw new Error('Rule name not found.');
}
if (!ruleName) {
throw new Error('Rule name not found.');
}

const ruleAssertions = assertions[ruleName];
const ruleAssertions = assertions[ruleName];

if (!ruleAssertions) {
throw new Error('No assertions available for rule "' + ruleName + '".');
}
if (!ruleAssertions) {
throw new Error('No assertions available for rule "' + ruleName + '".');
}

if (ruleAssertions.invalid.length) {
exampleBody += 'The following patterns are considered problems:\n\n```js\n' + ruleAssertions.invalid.join('\n\n') + '\n```\n\n';
}
if (ruleAssertions.invalid.length) {
exampleBody +=
'The following patterns are considered problems:\n\n```js\n' +
ruleAssertions.invalid.join('\n\n') +
'\n```\n\n';
}

if (ruleAssertions.valid.length) {
exampleBody += 'The following patterns are not considered problems:\n\n```js\n' + ruleAssertions.valid.join('\n\n') + '\n```\n\n';
}
if (ruleAssertions.valid.length) {
exampleBody +=
'The following patterns are not considered problems:\n\n```js\n' +
ruleAssertions.valid.join('\n\n') +
'\n```\n\n';
}

return exampleBody;
});
return exampleBody;
},
);

fs.writeFileSync(readmeDocumentPath, documentBody);
};
Expand Down
Loading