Skip to content
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

Run prettier and lint #806

Merged
merged 5 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ module.exports = {
"@typescript-eslint/camelcase": 0,
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-empty-function": "off",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This rule exception was added to suppress the following npm run lint errors:

nielsfaber/scheduler-card/src/data/websockets.ts
  48:20  error  Unexpected empty arrow function 'confirm'  @typescript-eslint/no-empty-function
  49:19  error  Unexpected empty arrow function 'cancel'   @typescript-eslint/no-empty-function

"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-use-before-define": "off",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This rule exception was added to suppress the following npm run lint errors:

nielsfaber/scheduler-card/src/standard-configuration/standardActions.ts
  35:28  error  'parseAction' was used before it was defined          @typescript-eslint/no-use-before-define
  79:16  error  'parseActionVariable' was used before it was defined  @typescript-eslint/no-use-before-define

nielsfaber/scheduler-card/src/standard-configuration/standardStates.ts
  38:33  error  'getStateName' was used before it was defined  @typescript-eslint/no-use-before-define

nielsfaber/scheduler-card/src/standard-configuration/variables.ts
  47:12  error  'parseListVariable' was used before it was defined                                                                                                   @typescript-eslint/no-use-before-define
  49:12  error  'parseLevelVariable' was used before it was defined                                                                                                  @typescript-eslint/no-use-before-define

"@typescript-eslint/ban-ts-ignore": "off"
}
};
21 changes: 21 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Contributing

Thank you for your interest in contributing to this project!

## Building

* Install Node.js (latest LTS release).
* On Linux, macOS, or Windows WSL, consider using [nvm.sh](https://github.com/nvm-sh/nvm/blob/master/README.md)
* On Windows native, see [Nodejs.org](https://nodejs.org/)
* `git clone https://github.com/nielsfaber/scheduler-card.git`
* `cd scheduler-card`
* `npm install --no-package-lock`
* `npm start` # To develop interactively
* `npm run build` # Run lint, prettier, rollup (update 'dist/scheduler-card.js')


## Codebase rewrite

Please note that a major rewrite of the codebase is ongoing as of March 2024. If you are
planning on submitting a significant contribution, get in touch to request a branch for
the new version to be published so that you can rebase your work on it.
8 changes: 1 addition & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"description": "Scheduler card for Lovelace",
"main": "dist/scheduler-card.js",
"scripts": {
"build": "npm run lint && npm run rollup && npm run babel",
"build": "npm run lint && npm run format && npm run rollup",
"rollup": "rollup -c",
"babel": "babel dist/scheduler-card.js --out-file dist/scheduler-card.js",
"lint": "eslint src/**/*.ts --fix",
"format": "prettier --write '**/*.ts'",
"start": "rollup -c --watch"
Expand All @@ -22,9 +21,6 @@
},
"homepage": "https://github.com/nielsfaber/scheduler-card#readme",
"dependencies": {
"@babel/core": "^7.6.4",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-decorators": "^7.4.0",
"@formatjs/intl-utils": "^3.8.4",
"@mdi/js": "^6.4.95",
"@typescript-eslint/eslint-plugin": "^2.6.0",
Expand All @@ -38,7 +34,6 @@
"home-assistant-js-websocket": "^5.7.0",
"lit": "^2.0.0",
"rollup": "^1.32.1",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
Expand All @@ -49,7 +44,6 @@
"typescript": "^3.6.4"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"eslint": "^6.8.0",
"prettier": "1.19.1",
"rollup-plugin-visualizer": "^4.2.0"
Expand Down
4 changes: 0 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import nodeResolve from 'rollup-plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import babel from 'rollup-plugin-babel';
import json from 'rollup-plugin-json';
import { terser } from 'rollup-plugin-terser';
import commonjs from 'rollup-plugin-commonjs';
Expand All @@ -14,9 +13,6 @@ const plugins = [
}),
typescript(),
json(),
babel({
exclude: 'node_modules/**',
}),
visualizer(),
terser(),
];
Expand Down
57 changes: 31 additions & 26 deletions src/components/timeslot-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ export class TimeslotEditor extends LitElement {
if (!!icons) {
return html`
<span style="margin-left: auto; margin-right: auto">
${icons.map((icon) => html`<ha-icon icon="${icon}"></ha-icon>`)}
${icons.map(
icon =>
html`
<ha-icon icon="${icon}"></ha-icon>
`
)}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The changes to this file are a result of running npm run format. (I did not edit this file “manually”.)

</span>
`;
}
Expand Down Expand Up @@ -170,8 +175,7 @@ export class TimeslotEditor extends LitElement {
</div>
`
: ''}
${i > 0 ? this.renderTooltip(i) : ''}
${content}
${i > 0 ? this.renderTooltip(i) : ''} ${content}
</div>
`;
});
Expand Down Expand Up @@ -258,29 +262,30 @@ export class TimeslotEditor extends LitElement {
if (!entry.actions) return;

return unique(
entry.actions.map(action => {
const actionConfig = this.actions.find(e => compareActions(e, action, true));
if (!actionConfig) return [];

if (
actionConfig.variables &&
Object.keys(actionConfig.variables).some(field => action.service_data && field in action.service_data)
) {
return Object.entries(actionConfig.variables)
.filter(([field]) => action.service_data && field in action.service_data)
.map(([field, variable]) => {
const value = action.service_data![field];
if (variable.type == EVariableType.List) {
variable = variable as ListVariable;
const listItem = variable.options.find(e => e.value == value);
return listItem?.icon;
} else return undefined;
});
}
return [actionConfig.icon];
})
.reduce((prev, icons) => [...prev, ...icons], [])
.filter((icon) => !!icon)
entry.actions
.map(action => {
const actionConfig = this.actions.find(e => compareActions(e, action, true));
if (!actionConfig) return [];

if (
actionConfig.variables &&
Object.keys(actionConfig.variables).some(field => action.service_data && field in action.service_data)
) {
return Object.entries(actionConfig.variables)
.filter(([field]) => action.service_data && field in action.service_data)
.map(([field, variable]) => {
const value = action.service_data![field];
if (variable.type == EVariableType.List) {
variable = variable as ListVariable;
const listItem = variable.options.find(e => e.value == value);
return listItem?.icon;
} else return undefined;
});
}
return [actionConfig.icon];
})
.reduce((prev, icons) => [...prev, ...icons], [])
.filter(icon => !!icon)
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/standard-configuration/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export const parseVariable = (
const res =
'template' in config && isDefined(config.template)
? { ...omit(config, 'template'), ...config.template(stateObj, hass) }
: <ListVariableConfig | LevelVariableConfig | TextVariableConfig>{ ...config };
: ({ ...config } as ListVariableConfig | LevelVariableConfig | TextVariableConfig);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The changes to this file were done “manually” by me, in order to address the following npm run lint errors:

$ npm run lint
...
nielsfaber/scheduler-card/src/standard-configuration/variables.ts
  44:9   error  Use 'as ListVariableConfig | LevelVariableConfig | TextVariableConfig' instead of '<ListVariableConfig | LevelVariableConfig | TextVariableConfig>'  @typescript-eslint/consistent-type-assertions
  51:12  error  Use 'as TextVariableConfig' instead of '<TextVariableConfig>'                                                                                        @typescript-eslint/consistent-type-assertions


if ('options' in res) {
return parseListVariable(res, stateObj);
} else if ('min' in res && 'max' in res) {
return parseLevelVariable(res, stateObj);
} else {
return <TextVariableConfig>res;
return res as TextVariableConfig;
}
};

Expand Down