mirror of
https://github.com/grafana/grafana.git
synced 2025-02-03 12:11:09 -06:00
Betterer: Add our own regexp matcher (#79448)
* Add betterer rule for gf-form * Betterer: Write generic regexp matcher * Add space * Update lockfile * Update comments * Add comment with notice
This commit is contained in:
parent
ce1450d4d3
commit
8d529bc4cb
1231
.betterer.results
1231
.betterer.results
File diff suppressed because it is too large
Load Diff
28
.betterer.ts
28
.betterer.ts
@ -12,12 +12,18 @@ const eslintPathsToIgnore = [
|
||||
'public/app/plugins/panel/graph', // will be removed alongside angular
|
||||
];
|
||||
|
||||
// Avoid using functions that report the position of the issues, as this causes a lot of merge conflicts
|
||||
export default {
|
||||
'better eslint': () =>
|
||||
countEslintErrors()
|
||||
.include('**/*.{ts,tsx}')
|
||||
.exclude(new RegExp(eslintPathsToIgnore.join('|'))),
|
||||
'no undocumented stories': () => countUndocumentedStories().include('**/!(*.internal).story.tsx'),
|
||||
'no gf-form usage': () =>
|
||||
regexp(
|
||||
/gf-form/gm,
|
||||
'gf-form usage has been deprecated. Use a component from @grafana/ui or custom CSS instead.'
|
||||
).include('**/*.{ts,tsx,html}'),
|
||||
};
|
||||
|
||||
function countUndocumentedStories() {
|
||||
@ -38,6 +44,28 @@ function countUndocumentedStories() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic regexp pattern matcher, similar to @betterer/regexp.
|
||||
* The only difference is that the positions of the errors are not reported, as this may cause a lot of merge conflicts.
|
||||
*/
|
||||
function regexp(pattern: RegExp, issueMessage: string) {
|
||||
return new BettererFileTest(async (filePaths, fileTestResult) => {
|
||||
await Promise.all(
|
||||
filePaths.map(async (filePath) => {
|
||||
const fileText = await fs.readFile(filePath, 'utf8');
|
||||
const matches = fileText.match(pattern);
|
||||
if (matches) {
|
||||
// File contents doesn't matter, since we're not reporting the position
|
||||
const file = fileTestResult.addFile(filePath, '');
|
||||
matches.forEach(() => {
|
||||
file.addIssue(0, 0, issueMessage);
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function countEslintErrors() {
|
||||
return new BettererFileTest(async (filePaths, fileTestResult, resolver) => {
|
||||
const { baseDirectory } = resolver;
|
||||
|
@ -81,7 +81,6 @@
|
||||
"@betterer/betterer": "5.4.0",
|
||||
"@betterer/cli": "5.4.0",
|
||||
"@betterer/eslint": "5.4.0",
|
||||
"@betterer/regexp": "5.4.0",
|
||||
"@cypress/webpack-preprocessor": "6.0.0",
|
||||
"@emotion/eslint-plugin": "11.11.0",
|
||||
"@grafana/eslint-config": "6.0.1",
|
||||
|
12
yarn.lock
12
yarn.lock
@ -1744,17 +1744,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@betterer/regexp@npm:5.4.0":
|
||||
version: 5.4.0
|
||||
resolution: "@betterer/regexp@npm:5.4.0"
|
||||
dependencies:
|
||||
"@betterer/betterer": "npm:^5.4.0"
|
||||
"@betterer/errors": "npm:^5.3.0"
|
||||
tslib: "npm:^2.3.1"
|
||||
checksum: bcbb2c94aa5673755e21415e41b5d405bb491867606ce7fab1a1e7987ef0231b50966b2e8d419a0b5ec1ca56f01d255580ea25580c92f3f9267fe1fa53a20aef
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@betterer/render@npm:^5.3.4":
|
||||
version: 5.3.4
|
||||
resolution: "@betterer/render@npm:5.3.4"
|
||||
@ -17309,7 +17298,6 @@ __metadata:
|
||||
"@betterer/betterer": "npm:5.4.0"
|
||||
"@betterer/cli": "npm:5.4.0"
|
||||
"@betterer/eslint": "npm:5.4.0"
|
||||
"@betterer/regexp": "npm:5.4.0"
|
||||
"@cypress/webpack-preprocessor": "npm:6.0.0"
|
||||
"@daybrush/utils": "npm:1.13.0"
|
||||
"@emotion/css": "npm:11.11.2"
|
||||
|
Loading…
Reference in New Issue
Block a user