Skip to content

Commit

Permalink
Add ESLint, fix the issues (#11)
Browse files Browse the repository at this point in the history
Not too much going on. I like to use the triple-equals rule; it's not
always necessary to use triple-equals but I think it's better to be
consistent. The rest of the fixes are typing-related.
  • Loading branch information
oyamauchi authored Aug 4, 2023
1 parent 4d54869 commit 141aaa4
Show file tree
Hide file tree
Showing 10 changed files with 619 additions and 32 deletions.
11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
env: { node: true },
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
ignorePatterns: ['build'],
rules: {
eqeqeq: ['error', 'always'],
},
};
1 change: 1 addition & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineConfig } from 'cypress';
export default defineConfig({
projectId: '4uypg2',
e2e: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
setupNodeEvents(on, config) {
// implement node event listeners here
},
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"serve:widget": "parcel serve ./src/*.html --dist-dir build",
"cypress:open": "cypress open",
"cypress:run": "cypress run",
"lint": "prettier --check ."
"lint": "prettier --check . && eslint ."
},
"browserslist": {
"production": [
Expand All @@ -30,7 +30,10 @@
},
"devDependencies": {
"@swc/helpers": "^0.4.14",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"cypress": "^12.6.0",
"eslint": "^8.45.0",
"parcel": "v2.8.3",
"postcss": "^8.4.21",
"postcss-modules": "^6.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/calculator-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ const TAX_FILING_OPTIONS: OptionParam[] = [
const HOUSEHOLD_SIZE_OPTIONS: OptionParam[] = [1, 2, 3, 4, 5, 6, 7, 8].map(
count => {
return {
label: `${count} ${count == 1 ? 'person' : 'people'}`,
label: `${count} ${count === 1 ? 'person' : 'people'}`,
value: count.toString(),
} as OptionParam;
},
);

export const formTemplate = (
[zip, ownerStatus, householdIncome, taxFiling, householdSize]: Array<string>,
onSubmit: Function,
onSubmit: (e: SubmitEvent) => void,
) => html`
<div class="card card-content">
<h1>How much money will you get with the Inflation Reduction Act?</h1>
Expand Down
14 changes: 10 additions & 4 deletions src/calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { baseStyles, cardStyles, gridStyles } from './styles';
import { formTemplate, formStyles } from './calculator-form';
import { detailsStyles, detailsTemplate } from './incentive-details';
import { summaryStyles, summaryTemplate } from './incentive-summary';
import { FilingStatus, OwnerStatus } from './calculator-types';
import {
FilingStatus,
ICalculatedIncentiveResults,
OwnerStatus,
} from './calculator-types';

const loadedTemplate = (
results: any,
results: ICalculatedIncentiveResults,
hideDetails: boolean,
hideSummary: boolean,
) => html`
Expand All @@ -20,9 +24,11 @@ const loadingTemplate = () => html`
<div class="card card-content">Loading...</div>
`;

const errorTemplate = (error: any) => html`
const errorTemplate = (error: unknown) => html`
<div class="card card-content">
${error.message || 'Error loading incentives.'}
${typeof error === 'object' && error && 'message' in error && error.message
? error.message
: 'Error loading incentives.'}
</div>
`;

Expand Down
4 changes: 2 additions & 2 deletions src/currency-input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LitElement, css, html, PropertyValues } from 'lit';
import { LitElement, html, PropertyValues } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { ref } from 'lit/directives/ref';
import AutoNumeric from 'autonumeric';
Expand Down Expand Up @@ -48,7 +48,7 @@ export class CurrencyInput extends LitElement {

onKeydown(event: KeyboardEvent) {
// this simulates submit on the host form, just like if you hit Enter in a regular <input>
if (event.key == 'Enter') {
if (event.key === 'Enter') {
const element: CurrencyInput = event.target as CurrencyInput;
element.internals?.form?.requestSubmit();
}
Expand Down
12 changes: 6 additions & 6 deletions src/incentive-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ const linkButtonStyles = css`
export const detailsStyles = [linkButtonStyles, tableStlyes];

function formatAmount(amount: number, amount_type: AmountType) {
if (amount_type == 'percent') {
if (amount_type === 'percent') {
return `${Math.round(amount * 100)}%`;
} else if (amount_type == 'dollar_amount') {
if (amount == 0) {
} else if (amount_type === 'dollar_amount') {
if (amount === 0) {
return 'N/A';
} else {
return `$${amount.toLocaleString()}`;
Expand All @@ -84,10 +84,10 @@ function formatAmount(amount: number, amount_type: AmountType) {
}

function formatStartDate(start_date: number, type: IncentiveType) {
if (start_date == 2022) {
if (start_date === 2022) {
return html`<em>Available Now!</em>`;
} else if (start_date == 2023) {
if (type == 'pos_rebate') {
} else if (start_date === 2023) {
if (type === 'pos_rebate') {
return html`Late 2023`;
} else {
return html`<em>Available Now!</em>`;
Expand Down
9 changes: 3 additions & 6 deletions src/incentive-summary.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { html, css, nothing } from 'lit';
import {
ICalculatedIncentiveResults,
IIncentiveRecord,
} from './calculator-types';
import { html, css, nothing, TemplateResult } from 'lit';
import { ICalculatedIncentiveResults } from './calculator-types';
import { lightningBolt } from './icons';

export const summaryStyles = css`
Expand Down Expand Up @@ -103,7 +100,7 @@ const numberTemplate = (
label: string,
value: number,
fancy?: boolean,
extra?: TemplateResult,
extra?: TemplateResult | typeof nothing,
) => html`
<div class="summary-number">
<div
Expand Down
2 changes: 1 addition & 1 deletion src/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const select = ({
?required=${required}
tabindex="${ifDefined(tabIndex)}"
>
${options.map(o => option(o, o.value == currentValue))}
${options.map(o => option(o, o.value === currentValue))}
</select>
<span class="focus"></span>
</div>
Expand Down
Loading

1 comment on commit 141aaa4

@vercel
Copy link

@vercel vercel bot commented on 141aaa4 Aug 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.