Skip to content

Commit

Permalink
chore: [#174293075,#174458516] Migrate from tslint to eslint (#2169)
Browse files Browse the repository at this point in the history
* start porting from tslint to eslint and upgrade prettier

* configure prettier and clean eslint config

* add tslint ignore

* refine settings

* fix eslint

* fix eslint

* fix eslint

* fix lint

* migrate to default import image comply with eslint

* fix lint

* fix ban types

* fix eslint

* fix import order

* fix danger

* fix danger

* replace operator

* prettify all with the latest version

* add missing rule "spaced-comment"

* add missing rules

* update rules

* add missing rules

* add missing rules

* add arrow-body-style

* restore array rule

* add missing rules

* add no-floating-promises rule

* no-unused-expression

* complete mapping rules for @typescript-eslint

* rename lint-typescript to eslint in circleci

* add missing rules

* add functional rules

* add sonar

* remove tslint

* remove unused plugin

* missing yarn lock

* merge Dangerfile.ts

* [#174293075] lint fixes

Co-authored-by: Matteo Boschi <[email protected]>
  • Loading branch information
fabriziofff and Undermaken authored Sep 1, 2020
1 parent f1a4432 commit 1cc7335
Show file tree
Hide file tree
Showing 329 changed files with 2,360 additions and 2,718 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:
- run: "bash <(curl -s https://codecov.io/bash)"

# Runs Danger checks on PR
lint-typescript:
eslint:
<<: *defaults_js

steps:
Expand Down Expand Up @@ -466,7 +466,7 @@ workflows:

- run-tests

- lint-typescript
- eslint

- run-danger:
filters:
Expand Down Expand Up @@ -519,7 +519,7 @@ workflows:
branches:
ignore: /.*/

- lint-typescript:
- eslint:
filters:
tags:
only: *release_tag
Expand All @@ -538,7 +538,7 @@ workflows:
requires:
- compile-typescript
- run-tests
- lint-typescript
- eslint
filters:
tags:
only: *release_tag
Expand Down
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locales/locales.ts
ts/utils/__tests__/xss.test.ts
definitions/*
93 changes: 93 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
module.exports = {
root: true,
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:sonarjs/recommended",
"prettier",
"prettier/@typescript-eslint"
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
sourceType: "module"
},
plugins: ["@typescript-eslint", "react", "import", "functional", "sonarjs"],
rules: {
"no-case-declarations": "off",
"no-inner-declarations": "off",
"prefer-const": "error",
curly: "error",
"spaced-comment": ["error", "always", { block: { balanced: true } }],
radix: "error",
"one-var": ["error", "never"],
"object-shorthand": "error",
"no-var": "error",
"no-param-reassign": "error",
"no-underscore-dangle": "error",
"no-undef-init": "error",
"no-throw-literal": "error",
"no-new-wrappers": "error",
"no-eval": "error",
"no-console": "error",
"no-caller": "error",
"no-bitwise": "error",
eqeqeq: ["error", "smart"],
"max-classes-per-file": ["error", 1],
"guard-for-in": "error",
complexity: "error",
"arrow-body-style": "error",
"import/order": "error",
"@typescript-eslint/no-unused-vars": "off",
// Enable if we want to enforce the return type for all the functions
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-inferrable-types": "off",
// TODO: added for compatibility. Removing this line we have to remove all the any usage in the code
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/array-type": [
"error",
{
default: "generic"
}
],
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/dot-notation": "error",
"@typescript-eslint/member-delimiter-style": [
"error",
{
multiline: {
delimiter: "semi",
requireLast: true
},
singleline: {
delimiter: "semi",
requireLast: false
}
}
],
"@typescript-eslint/no-floating-promises": "error",
"no-unused-expressions": "off",
"@typescript-eslint/no-unused-expressions": ["error"],
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/restrict-plus-operands": "error",
semi: "off",
"@typescript-eslint/semi": ["error"],
"@typescript-eslint/unified-signatures": "error",
"react/prop-types": "off",
"react/display-name": "off",
"react/jsx-key": "error",
"react/jsx-no-bind": ["error", { allowArrowFunctions: true }],
"functional/no-let": "error",
"functional/immutable-data": "error",
"sonarjs/no-small-switch": "off",
"sonarjs/no-duplicate-string": "off"
},
settings: {
react: {
version: "detect"
}
}
};
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.13.0
10.18.0
3 changes: 0 additions & 3 deletions .prettierrc

This file was deleted.

7 changes: 3 additions & 4 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module.exports = {
bracketSpacing: false,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
trailingComma: "none",
arrowParens: "avoid",
parser: "typescript"
};
16 changes: 9 additions & 7 deletions Dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import { warn } from "danger";
// See https://github.com/teamdigitale/danger-plugin-digitalcitizenship/
import checkDangers from "danger-plugin-digitalcitizenship";
import { DangerDSLType } from "danger/distribution/dsl/DangerDSL";
import { none } from "fp-ts/lib/Option";
import {fromNullable, none} from "fp-ts/lib/Option";
import {
allStoriesSameType,
getChangelogPrefixByStories,
getChangelogScope,
getPivotalStoriesFromPrTitle,
getRawTitle
getPivotalStoriesFromPrTitle
} from "./scripts/changelog/ts/changelog";

declare var danger: DangerDSLType;
declare const danger: DangerDSLType;

const multipleTypesWarning =
"Multiple stories with different types are associated with this Pull request.\n" +
Expand Down Expand Up @@ -41,19 +40,22 @@ const updatePrTitleForChangelog = async () => {
.map(s => `(${s})`)
.getOrElse("");

const rawTitle = getRawTitle(danger.github.pr.title);
const cleanChangelogRegex = /^(fix(\(.+\))?!?: |feat(\(.+\))?!?: |chore(\(.+\))?!?: )?(.*)$/;
const title = fromNullable(danger.github.pr.title.match(cleanChangelogRegex))
.map(matches => matches.pop() || danger.github.pr.title)
.getOrElse(danger.github.pr.title);

maybePrTag.map(tag =>
danger.github.api.pulls.update({
owner: danger.github.thisPR.owner,
repo: danger.github.thisPR.repo,
pull_number: danger.github.thisPR.number,
title: `${tag}${scope}: ${rawTitle}`
title: `${tag}${scope}: ${title}`
})
);
};

checkDangers();
updatePrTitleForChangelog()
void updatePrTitleForChangelog()
.then()
.catch();
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"packager:clear": "rm -rf $TMPDIR/react-native-packager-cache-* && rm -rf $TMPDIR/metro-bundler-cache-*",
"bundle:android": "node node_modules/react-native/local-cli/cli.js bundle --platform android --dev true --entry-file index.js --bundle-output ./bundles/index.android.bundle",
"tsc:noemit": "tsc --noemit",
"lint": "tslint -p . -c tslint.json -t verbose",
"lint-autofix": "tslint -p . -c tslint.json -t verbose --fix",
"lint": "eslint . -c .eslintrc.js --ext .ts,.tsx",
"lint-autofix": "eslint . -c .eslintrc.js --ext .ts,.tsx --fix",
"check_urls": "python3 scripts/check_urls.py",
"generate:pagopa-api-definitions": "rimraf definitions/pagopa && mkdir -p definitions/pagopa && gen-api-models --api-spec $npm_package_pagopa_api --out-dir ./definitions/pagopa --no-strict --request-types --response-decoders --default-error-type undefined",
"generate:mock-google-services-json": "cp mock-google-services.json ./android/app/google-services.json",
Expand All @@ -41,11 +41,15 @@
"@react-native-community/async-storage": "^1.6.1",
"@react-native-community/cameraroll": "^4.0.0",
"@redux-saga/testing-utils": "^1.1.3",
"@typescript-eslint/eslint-plugin": "^3.10.1",
"abort-controller": "^1.0.2",
"async-mutex": "^0.1.3",
"buffer": "^4.9.1",
"color": "^3.0.0",
"date-fns": "^1.29.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-functional": "^3.0.2",
"eslint-plugin-sonarjs": "^0.5.0",
"fp-ts": "1.12.0",
"front-matter": "^4.0.2",
"hoist-non-react-statics": "^3.0.1",
Expand Down Expand Up @@ -151,15 +155,17 @@
"@types/stacktrace-js": "^0.0.32",
"@types/uuid": "^3.4.4",
"@types/validator": "^9.4.2",
"@typescript-eslint/parser": "^3.10.1",
"abortcontroller-polyfill": "1.3.0",
"babel-jest": "^25.1.0",
"babel-preset-react-native": "^4.0.1",
"chalk": "^2.4.1",
"danger": "^10.3.0",
"danger-plugin-digitalcitizenship": "^0.3.1",
"eslint": "^6.5.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-react": "^7.20.6",
"fs-extra": "^7.0.0",
"italia-tslint-rules": "^1.1.0",
"italia-utils": "^4.1.1",
"jest": "^25.1.0",
"js-yaml": "^3.13.1",
Expand All @@ -171,14 +177,13 @@
"pivotaljs": "^1.0.3",
"plist": "^3.0.1",
"postinstall-postinstall": "^1.0.0",
"prettier": "1.14.2",
"prettier": "2.1.0",
"react-test-renderer": "16.13.1",
"redux-saga-test-plan": "4.0.0-rc.3",
"rn-nodeify": "^10.0.1",
"standard-version": "^8.0.2",
"ts-jest": "^25.1.0",
"ts-node": "^7.0.1",
"tslint": "5.20.0",
"typescript": "^3.9.7"
},
"resolutions": {
Expand Down
17 changes: 6 additions & 11 deletions scripts/changelog/ts/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ export const getStoryChangelogScope = (
if (maybeChangelogScopeTag.length > 1) {
return left(
new Error(
`Multiple labels match the expression \`${regex}\` for the story [#${
story.id
}].\n
`Multiple labels match the expression \`${regex}\` for the story [#${story.id}].\n
It is not possible to assign a single scope to this pull request!`
)
);
Expand All @@ -130,11 +128,7 @@ export const getStoryChangelogScope = (
if (maybeProjectScope.isSome() && maybeChangelogScopeTag.length >= 1) {
return left(
new Error(
`The story [#${story.id}] have the project_id ${
story.project_id
} associated with the scope ${
maybeProjectScope.value
} but also have labels matching the expression \`${regex}\`.\n
`The story [#${story.id}] have the project_id ${story.project_id} associated with the scope ${maybeProjectScope.value} but also have labels matching the expression \`${regex}\`.\n
It is not possible to assign a single scope to this pull request!`
)
);
Expand Down Expand Up @@ -180,9 +174,10 @@ export const getChangelogScope = (
// if there is some error, forward the errors
if (eitherChangelogScopes.some(scope => scope.isLeft())) {
return left(
eitherChangelogScopes.reduce<ReadonlyArray<Error>>((acc, val) => {
return val.isLeft() ? [...acc, val.value] : acc;
}, [])
eitherChangelogScopes.reduce<ReadonlyArray<Error>>(
(acc, val) => (val.isLeft() ? [...acc, val.value] : acc),
[]
)
);
}
const scopesList = eitherChangelogScopes
Expand Down
37 changes: 17 additions & 20 deletions scripts/make-locales.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
/**
* This script converts the translations from the "locales"
* directory into a typescript file that can be bundled with
Expand All @@ -13,12 +14,11 @@
* I18N_IGNORE_LOCALE_ERRORS=1 Ignore locale validation errors.
* I18N_MASTER_LOCALE=it Sets a different master locale.
*/
// tslint:disable:no-console

import * as path from "path";
import chalk from "chalk";
import * as fs from "fs-extra";
import * as yaml from "js-yaml";
import * as path from "path";
import * as prettier from "prettier";

interface LocaleDoc {
Expand All @@ -44,26 +44,20 @@ const IncludeYamlType = (includeRoot: string) =>
new yaml.Type("!include", {
kind: "scalar",

resolve: (data: any) => {
return (
resolve: (data: any) => (
data !== null &&
typeof data === "string" &&
path // included file must be under includeRoot
.normalize(path.join(includeRoot, data))
.startsWith(path.normalize(includeRoot)) &&
fs.statSync(path.join(includeRoot, data)).isFile()
);
},
),

construct: data => {
return fs.readFileSync(path.join(includeRoot, data)).toString();
},
construct: data => fs.readFileSync(path.join(includeRoot, data)).toString(),

instanceOf: String,

represent: (data: any) => {
return String(data);
}
represent: (data: any) => String(data)
});

/**
Expand Down Expand Up @@ -234,12 +228,12 @@ async function run(rootPath: string): Promise<void> {

// compare keys of locales with master keys
console.log(chalk.gray("[3/4]"), "Comparing keys...");
const checkedLocaleKeys: ReadonlyArray<
LocaleDocWithCheckedKeys
> = otherLocaleKeys.map(l => ({
...l,
...compareLocaleKeys(masterKeys.keys, l.keys)
}));
const checkedLocaleKeys: ReadonlyArray<LocaleDocWithCheckedKeys> = otherLocaleKeys.map(
l => ({
...l,
...compareLocaleKeys(masterKeys.keys, l.keys)
})
);

// look for locales that have missing or extra keys
const badLocales = checkedLocaleKeys.filter(
Expand All @@ -248,7 +242,7 @@ async function run(rootPath: string): Promise<void> {

if (badLocales.length > 0) {
badLocales.forEach(reportBadLocale);
if (!Boolean(process.env.I18N_IGNORE_LOCALE_ERRORS)) {
if (!process.env.I18N_IGNORE_LOCALE_ERRORS) {
throw Error("bad locales detected");
}
}
Expand All @@ -264,4 +258,7 @@ async function run(rootPath: string): Promise<void> {
}
}

run(root).then(() => console.log("done"), () => process.exit(1));
run(root).then(
() => console.log("done"),
() => process.exit(1)
);
Loading

0 comments on commit 1cc7335

Please sign in to comment.