Skip to content

Commit

Permalink
Merge pull request #806 from pdcastro/run-lint-prettier
Browse files Browse the repository at this point in the history
Run prettier and lint
  • Loading branch information
nielsfaber authored Mar 26, 2024
2 parents 0d91a69 + 3e1b822 commit f37290c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 39 deletions.
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",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-use-before-define": "off",
"@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>
`
)}
</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);

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

0 comments on commit f37290c

Please sign in to comment.