Skip to content

Commit

Permalink
chore: add Prettier + husky + lint-staged
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzhao committed Feb 6, 2025
1 parent 7199cd9 commit bd9c226
Show file tree
Hide file tree
Showing 56 changed files with 4,785 additions and 2,223 deletions.
53 changes: 14 additions & 39 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,23 @@
'use strict'
'use strict';
const eslintConfig = {
extends: [
'eslint:recommended'
],
extends: ['eslint:recommended', 'prettier'],
parserOptions: {
"ecmaVersion": "latest"
ecmaVersion: 'latest',
},
env: {
"es6": true,
"node": true
es6: true,
node: true,
},
plugins: [
'ava'
],
plugins: ['ava'],
rules: {
'ava/no-import-test-files': 0,
'ava/no-ignored-test-files': 0,
indent: [
'error',
2,
{
CallExpression: {
arguments: 'first'
},
SwitchCase: 1
}
],
'no-console': 0,
strict: 'error',
'comma-dangle': ['error', 'never'],
semi: ['error', 'never'],
'space-before-function-paren': ['error', 'always']
},
overrides: [
{
files: ["**/*.ts"],
files: ['**/*.ts'],
extends: [
'eslint:recommended',
'plugin:ava/recommended',
Expand All @@ -43,23 +26,15 @@ const eslintConfig = {
'plugin:promise/recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript'
'plugin:import/typescript',
'prettier',
],
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module'
sourceType: 'module',
},
rules: {
'comma-dangle': ['error', 'always-multiline'],
semi: ['error', 'always'],
'space-before-function-paren': ['error', {
"anonymous": "never",
"named": "never",
"asyncArrow": "always"
}]
}
}
]
}
},
],
};

module.exports = eslintConfig
module.exports = eslintConfig;
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ blank_issues_enabled: false
contact_links:
- name: Question
url: https://discord.gg/APGC3k5yaH
about: "Please ask questions about using Electron Packager in the official Electron Discord server, at the #electron-packager channel."
about: 'Please ask questions about using Electron Packager in the official Electron Discord server, at the #electron-packager channel.'
8 changes: 4 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'monthly'
2 changes: 1 addition & 1 deletion .github/workflows/canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: electron-nightly Canary

on:
schedule:
- cron: "15 8 * * *"
- cron: '15 8 * * *'

jobs:
build:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ jobs:
id: generate-token
with:
creds: ${{ secrets.GH_APP_CREDS }}
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag: v4.2.2
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag: v4.2.2
with:
token: ${{ steps.generate-token.outputs.token }}
- name: Fetch all git branches
run: git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # tag: v4.2.0
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # tag: v4.2.0
with:
node-version: lts/*
- run: yarn install --frozen-lockfile
- run: yarn run docs:build
- name: Prepare docs
uses: malept/github-action-gh-pages@f7952a65c4b763dc84b824a530dc38bd375ac91e # tag: v1.4.0
uses: malept/github-action-gh-pages@f7952a65c4b763dc84b824a530dc38bd375ac91e # tag: v1.4.0
with:
defaultBranch: main
docsPath: typedoc
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/semantic.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Check Semantic Commit"
name: 'Check Semantic Commit'

on:
pull_request:
Expand All @@ -13,8 +13,8 @@ permissions:
jobs:
main:
permissions:
pull-requests: read # for amannn/action-semantic-pull-request to analyze PRs
statuses: write # for amannn/action-semantic-pull-request to mark status of analyzed PR
pull-requests: read # for amannn/action-semantic-pull-request to analyze PRs
statuses: write # for amannn/action-semantic-pull-request to mark status of analyzed PR
name: Validate PR Title
runs-on: ubuntu-latest
steps:
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,27 @@ jobs:
- macos-latest
- ubuntu-latest
- windows-latest
runs-on: "${{ matrix.os }}"
runs-on: '${{ matrix.os }}'
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: "${{ matrix.node-version }}"
node-version: '${{ matrix.node-version }}'
cache: 'yarn'
- name: Setup CI Environment
run: test/ci/before_install.sh
- name: Install
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: ESLint Cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: |
.eslintcache
key: ${{ matrix.os }}-node-${{ hashFiles('*/yarn.lock', '*/.eslintrc.js') }}
- name: Electron Cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ npm-debug.log
dist/
src/targets.js
coverage.lcov
.eslintcache
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
18 changes: 10 additions & 8 deletions bin/electron-packager.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/usr/bin/env node

'use strict'
'use strict';

/* eslint-disable no-var */
// WHY: not consts so that this file can load in Node < 4.0
var packageJSON = require('../package.json')
var semver = require('semver')
var packageJSON = require('../package.json');
var semver = require('semver');
if (!semver.satisfies(process.versions.node, packageJSON.engines.node)) {
console.error('CANNOT RUN WITH NODE ' + process.versions.node)
console.error('Electron Packager requires Node ' + packageJSON.engines.node + '.')
process.exit(1)
console.error('CANNOT RUN WITH NODE ' + process.versions.node);
console.error(
'Electron Packager requires Node ' + packageJSON.engines.node + '.',
);
process.exit(1);
}

var cli = require('../dist/cli')
cli.run(process.argv.slice(2))
var cli = require('../dist/cli');
cli.run(process.argv.slice(2));
18 changes: 15 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"junk": "^3.1.0",
"parse-author": "^2.0.0",
"plist": "^3.0.0",
"prettier": "^3.4.2",
"resedit": "^2.0.0",
"resolve": "^1.1.6",
"semver": "^7.1.3",
Expand All @@ -55,15 +56,18 @@
"@types/semver": "^7.5.8",
"@types/yargs-parser": "^21.0.2",
"@typescript-eslint/eslint-plugin": "7.2.0",
"@typescript-eslint/parser": "^6.9.1",
"@typescript-eslint/parser": "^8.2.3",
"ava": "^3.10.1",
"buffer-equal": "^1.0.0",
"copyfiles": "^2.4.1",
"eslint": "^8.52.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-ava": "^14.0.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^6.2.0",
"husky": "^9.1.7",
"lint-staged": "^15.4.3",
"lodash": "^4.17.21",
"nyc": "^15.0.0",
"pkg-up": "^4.0.0",
Expand All @@ -84,10 +88,11 @@
"coverage": "nyc ava test/index.js",
"coverage:report": "nyc report --reporter=text-lcov > coverage.lcov",
"docs:build": "npx typedoc",
"lint": "eslint .",
"lint": "prettier --check \"*.{ts,js,json,yml}\" && eslint . --cache",
"prepublish": "npm run build",
"pretest": "npm run build",
"test": "npm run lint && npm run coverage"
"test": "npm run lint && npm run coverage",
"prepare": "husky"
},
"directories": {
"test": "test"
Expand All @@ -106,5 +111,12 @@
},
"resolutions": {
"got": "11.8.5"
},
"lint-staged": {
"*.{json,yml}": "prettier --write",
"*.{js,ts}": [
"prettier --write",
"eslint --fix"
]
}
}
29 changes: 16 additions & 13 deletions src/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
declare module 'get-package-info' {
type Props = Array<string | string[]>
type Props = Array<string | string[]>;

export type GetPackageInfoResultSourceItem = {
/** path to the package.json file */
src: string
src: string;

/** property name */
prop: string
prop: string;

/** the `package.json` object */
pkg: Record<string, unknown>
}
pkg: Record<string, unknown>;
};

export type GetPackageInfoResult = {
source: Record<string, GetPackageInfoResultSourceItem>
values: Record<string, unknown>
}
source: Record<string, GetPackageInfoResultSourceItem>;
values: Record<string, unknown>;
};

function getPackageInfo (props: Props, dir: string): Promise<GetPackageInfoResult>
function getPackageInfo(
props: Props,
dir: string,
): Promise<GetPackageInfoResult>;

export type GetPackageInfoError = Error & {
missingProps: Props
result: GetPackageInfoResult
}
missingProps: Props;
result: GetPackageInfoResult;
};

export = getPackageInfo
export = getPackageInfo;
}
Loading

0 comments on commit bd9c226

Please sign in to comment.