Skip to content

Commit

Permalink
Use @typescript-eslint/recommended-type-checked for lint (#1184)
Browse files Browse the repository at this point in the history
`standard-with-typescript` [is
deprecated](#961).
A config is used:
https://typescript-eslint.io/users/configs#projects-with-type-checking

`package-lock.json` was recreated (removed, `npm install`, `git add` )
  • Loading branch information
atuchin-m authored Aug 20, 2024
1 parent 813d5f2 commit 6c8d43e
Show file tree
Hide file tree
Showing 15 changed files with 2,605 additions and 10,597 deletions.
13,126 changes: 2,560 additions & 10,566 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
"@types/node": "20.14.15",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"@typescript-eslint/eslint-plugin": "6.21.0",
"@typescript-eslint/parser": "6.21.0",
"@typescript-eslint/eslint-plugin": "8.2.0",
"commander": "12.1.0",
"css-loader": "5.2.7",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-config-standard-with-typescript": "39.1.1",
"eslint-plugin-licenses": "1.0.2",
"eslint-plugin-react": "7.35.0",
"file-loader": "6.2.0",
Expand All @@ -46,6 +44,7 @@
"ts-loader": "9.5.1",
"tsx": "4.17.0",
"typescript": "5.5.4",
"typescript-eslint": "8.2.0",
"webpack": "5.93.0",
"webpack-cli": "4.10.0",
"webpack-dev-server": "4.15.2"
Expand All @@ -55,9 +54,9 @@
"moduleResolution": "node",
"dependencies": {
"@protobuf-ts/runtime": "2.9.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router": "^6.15.0",
"react-router-dom": "^6.15.0"
"react": "18.2.0",
"react-dom": "18.2.0",
"react-router": "6.15.0",
"react-router-dom": "6.15.0"
}
}
20 changes: 18 additions & 2 deletions src/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ module.exports = {
version: 'detect',
},
},
extends: ['standard-with-typescript', 'prettier', 'plugin:react/recommended'],
env: {
browser: true,
node: true,
es6: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'prettier',
'plugin:react/recommended',
],
plugins: ['licenses', 'react'],
root: true,
parserOptions: {
Expand All @@ -24,7 +35,12 @@ module.exports = {
},
],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',

'licenses/header': [
2,
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/blocklists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Blocklist {
for (const line of patterns) {
if (line === '') continue;
const len = line.length;
if (len > 2 && line[0] === '/' && line[len - 1] === '/') {
if (len > 2 && line.startsWith('/') && line[len - 1] === '/') {
this.regexps.push(new RegExp(line.substring(1, len - 2)));
} else {
this.regexps.push(new RegExp(`^${line}$`));
Expand Down
12 changes: 5 additions & 7 deletions src/core/study_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class StudyDetails {
return;
}
const isKillSwitch = (s: string) => {
return s.match(/(K|k)ill(S|s)witch/) !== null;
return /(K|k)ill(S|s)witch/.test(s);
};

if (maxVersion != null) {
Expand Down Expand Up @@ -223,11 +223,9 @@ export class StudyDetails {
const enableFeatures = e.feature_association?.enable_feature;
const disabledFeatures = e.feature_association?.disable_feature;
this.isBlocklisted ||=
enableFeatures != null &&
enableFeatures.some((n) => isFeatureBlocklisted(n));
enableFeatures?.some((n) => isFeatureBlocklisted(n)) ?? false;
this.isBlocklisted ||=
disabledFeatures != null &&
disabledFeatures.some((n) => isFeatureBlocklisted(n));
disabledFeatures?.some((n) => isFeatureBlocklisted(n)) ?? false;

this.isKillSwitch ||= e.probability_weight > 0 && isKillSwitch(e.name);

Expand Down Expand Up @@ -261,9 +259,9 @@ export class StudyDetails {
}

const channel = study.filter?.channel;
if (channel != null && channel.includes(proto.Study.Channel.BETA))
if (channel?.includes(proto.Study.Channel.BETA))
this.channelTarget = StudyChannelTarget.BETA;
if (channel != null && channel.includes(proto.Study.Channel.STABLE))
if (channel?.includes(proto.Study.Channel.STABLE))
this.channelTarget = StudyChannelTarget.STABLE;
}

Expand Down
4 changes: 3 additions & 1 deletion src/finch_tracker/node_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export async function downloadUrl(url: string): Promise<Buffer> {
const data: any = [];
https
.get(url, (res) => {
res.on('data', (chunk) => data.push(chunk));
res.on('data', (chunk) => {
data.push(chunk);
});
res.on('end', () => {
resolve(Buffer.concat(data));
});
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const dirsToRemove = ['./src/finch_tracker/build', './src/web/public/bundle'];

program.description('Cleans build directories').action(main).parse();

async function main() {
function main() {
fs.readdirSync('src/proto/generated').forEach((file) => {
if (file.startsWith('proto_bundle')) {
fs.unlinkSync(`src/proto/generated/${file}`);
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/generate_proto_ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface Options {
generate_patch?: true;
}

async function main(options: Options) {
function main(options: Options) {
if (options.generate_patch) {
generateStudyProtoPatch();
return;
Expand All @@ -43,7 +43,7 @@ async function main(options: Options) {
function removeGeneratedFiles() {
const files = fs.readdirSync(protoGeneratedDir);
files.forEach((file) => {
if (file.match(/.*\.(ts|js)$/) !== null) {
if (/.*\.(ts|js)$/.test(file)) {
fs.unlinkSync(`${protoGeneratedDir}/${file}`);
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/seed_tools/commands/validate_seed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ describe('validate_seed command', () => {
let errorMock: jest.SpyInstance;
let exitMock: jest.SpyInstance;

beforeEach(async () => {
beforeEach(() => {
errorMock = jest.spyOn(console, 'error').mockImplementation();
exitMock = jest.spyOn(process, 'exit').mockImplementation();
});

afterEach(async () => {
afterEach(() => {
jest.restoreAllMocks();
});

Expand Down
2 changes: 1 addition & 1 deletion src/seed_tools/utils/diff_strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default async function diffStrings(
if (error.code === 1) {
// Remove root forward slashes from the temporary file paths as git diff
// does not include them.
const result = error.stdout
const result = (error.stdout as string)
.replaceAll(tmpFile1.replace(/^\//, ''), displayFileName1)
.replaceAll(tmpFile2.replace(/^\//, ''), displayFileName2);

Expand Down
1 change: 0 additions & 1 deletion src/seed_tools/utils/seed_validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ function doesVersionFieldRangeIntersect(
function doesDateRangeIntersect(
study1: ProcessedStudy,
study2: ProcessedStudy,
field: 'start_date',
): boolean {
const [start1, end1] = study1.date_range;
const [start2, end2] = study2.date_range;
Expand Down
2 changes: 1 addition & 1 deletion src/seed_tools/utils/study_json_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function jsonStudyReviever(
case 'end_date': {
const isIsoString =
typeof value === 'string' &&
value.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/) !== null;
/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(value);
if (!isIsoString) {
throw new Error(
`Invalid ${key} value "${value}", only ISO format with Z timezone is supported`,
Expand Down
2 changes: 1 addition & 1 deletion src/web/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export function CurrentStudyList(props: {
[props.studies, paramManager.currentSeed, paramManager.filter],
);

const studyList = studies?.map((study, i) => (
const studyList = studies?.map((study) => (
<StudyItem key={study.id} study={study} filter={paramManager.filter} />
));

Expand Down
6 changes: 3 additions & 3 deletions src/web/app/seed_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function loadFile(
url: string,
responseType: 'arraybuffer' | 'text',
): Promise<any> {
return await new Promise<any | undefined>((resolve, reject) => {
return await new Promise<any>((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', url, true /* async */);
xhr.responseType = responseType;
Expand All @@ -37,8 +37,8 @@ async function loadFile(
reject(new Error('HTTP status:' + xhr.status));
}
};
xhr.onerror = (err) => {
reject(err);
xhr.onerror = () => {
reject(new Error('XHR error'));
};
xhr.send(null);
});
Expand Down
2 changes: 1 addition & 1 deletion src/web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const path = require('path');

function isDevMode(argv) {
Expand Down

0 comments on commit 6c8d43e

Please sign in to comment.