chore(CI): add super-linter to help lint workspace (#137)

This commit is contained in:
Miraculous Owonubi 2022-02-16 05:40:55 +01:00 committed by GitHub
parent 980c9af668
commit d5a736008c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 253 additions and 196 deletions

View File

@ -19,6 +19,10 @@
"plugins": [ "plugins": [
"prettier" "prettier"
], ],
"ignorePatterns": [
"**/*.json",
"**/*.json5"
],
"rules": { "rules": {
"prettier/prettier": [ "prettier/prettier": [
1, 1,

5
.github/FUNDING.yml vendored
View File

@ -1,4 +1,7 @@
custom: ['https://commerce.coinbase.com/checkout/466d703a-fbd7-41c9-8366-9bdd3e240755'] ---
custom:
- https://commerce.coinbase.com/checkout/466d703a-fbd7-41c9-8366-9bdd3e240755
ko_fi: miraclx ko_fi: miraclx
liberapay: miraclx liberapay: miraclx
patreon: miraclx patreon: miraclx

10
.github/linters/.jscpd.json vendored Normal file
View File

@ -0,0 +1,10 @@
{
"threshold": 0,
"reporters": [
"consoleFull"
],
"ignore": [
"**/.github/workflows/tests.yml"
],
"absolute": true
}

8
.github/workflows/ci-prep.sh vendored Normal file → Executable file
View File

@ -1,6 +1,8 @@
#!/usr/bin/env bash
RG_SRC="$(which rg)" RG_SRC="$(which rg)"
rg() { rg() {
printf "rg: pattern: /$*/" > /dev/stderr printf 'rg: pattern: %s' "/$*/" >/dev/stderr
if $RG_SRC --fixed-strings --passthru "$@"; then if $RG_SRC --fixed-strings --passthru "$@"; then
echo " (matched)" >/dev/stderr echo " (matched)" >/dev/stderr
else else
@ -16,7 +18,7 @@ freyr() {
i=$($RG_SRC -n '.' .freyr_log | $RG_SRC --fixed-strings '[•] Embedding Metadata' | cut -d':' -f1) i=$($RG_SRC -n '.' .freyr_log | $RG_SRC --fixed-strings '[•] Embedding Metadata' | cut -d':' -f1)
if [[ $i ]]; then if [[ $i ]]; then
echo "::group::[$attempts/3] View Download Status" echo "::group::[$attempts/3] View Download Status"
tail +$i .freyr_log tail +"$i" .freyr_log
echo "::endgroup::" echo "::endgroup::"
fi fi
} }
@ -36,7 +38,7 @@ exec_retry() {
echo "::endgroup::" echo "::endgroup::"
echo "::group::View Files" echo "::group::View Files"
STAGE=$(realpath --relative-to=../.. .) && cd ../.. STAGE=$(realpath --relative-to=../.. .) && cd ../..
tree -sh $STAGE tree -sh "$STAGE"
echo "::endgroup::" echo "::endgroup::"
} }

View File

@ -1,3 +1,4 @@
---
name: publish name: publish
on: on:

View File

@ -1,3 +1,4 @@
---
name: tests name: tests
on: on:
@ -238,3 +239,28 @@ jobs:
- name: Test Docker Build - name: Test Docker Build
run: docker build -t freyrcli/freyrjs . run: docker build -t freyrcli/freyrjs .
linter:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0
- name: Install Dependencies
run: npm ci
- name: Lint Code Base
uses: github/super-linter@v4
env:
VALIDATE_ALL_CODEBASE: false
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LINTER_RULES_PATH: /
JAVASCRIPT_ES_CONFIG_FILE: .eslintrc
JSCPD_CONFIG_FILE: .github/linters/.jscpd.json
VALIDATE_JAVASCRIPT_STANDARD: false

View File

@ -5,6 +5,7 @@ LABEL maintainer="Miraculous Owonubi <omiraculous@gmail.com>" \
tag="alpine" tag="alpine"
# Install dependencies and clean cache # Install dependencies and clean cache
# hadolint ignore=DL3018
RUN apk add \ RUN apk add \
--no-cache \ --no-cache \
git \ git \
@ -26,6 +27,7 @@ RUN mkdir /bins \
ENV PATH "/bins:$PATH" ENV PATH "/bins:$PATH"
# Create freyr user and group # Create freyr user and group
# hadolint ignore=DL4006
RUN addgroup -g 1000 freyr \ RUN addgroup -g 1000 freyr \
&& adduser -DG freyr freyr \ && adduser -DG freyr freyr \
&& echo freyr:freyr | chpasswd && echo freyr:freyr | chpasswd

View File

@ -99,7 +99,9 @@
<details> <details>
<summary>ffmpeg >= v0.9</summary> <summary>ffmpeg >= v0.9</summary>
<!-- textlint-disable -->
Download for your individual platforms here <https://ffmpeg.org/download.html> Download for your individual platforms here <https://ffmpeg.org/download.html>
<!-- textlint-enable -->
- Windows + macOS: - Windows + macOS:
- Ensure to extract the `ffmpeg` binary from the compressed file, if it's in one. - Ensure to extract the `ffmpeg` binary from the compressed file, if it's in one.
@ -209,6 +211,7 @@ Usage: freyr [options] [query...]
<details> <details>
<summary> <code>freyr get --help</code> </summary> <summary> <code>freyr get --help</code> </summary>
<!-- editorconfig-checker-disable -->
```console ```console
____ ____
/ __/_______ __ _______ / __/_______ __ _______
@ -294,6 +297,7 @@ Info:
their respective folders. However, a m3u8 playlist file is generated in their respective folders. However, a m3u8 playlist file is generated in
the base directory with the name of the playlist that lists the tracks the base directory with the name of the playlist that lists the tracks
``` ```
<!-- editorconfig-checker-enable -->
</details> </details>
@ -302,6 +306,7 @@ Info:
<details> <details>
<summary> <code>freyr spotify:track:5FNS5Vj69AhRGJWjhrAd01</code> </summary> <summary> <code>freyr spotify:track:5FNS5Vj69AhRGJWjhrAd01</code> </summary>
<!-- editorconfig-checker-disable -->
```console ```console
____ ____
/ __/_______ __ _______ / __/_______ __ _______
@ -353,6 +358,7 @@ Checking directory permissions...[done]
[•] Output bitrate: 320k [•] Output bitrate: 320k
=============================== ===============================
``` ```
<!-- editorconfig-checker-enable -->
</details> </details>
@ -361,6 +367,7 @@ Checking directory permissions...[done]
<details> <details>
<summary> <code> freyr https://music.apple.com/us/album/im-sorry-im-not-sorry-ep/1491795443 </code> </summary> <summary> <code> freyr https://music.apple.com/us/album/im-sorry-im-not-sorry-ep/1491795443 </code> </summary>
<!-- editorconfig-checker-disable -->
```console ```console
____ ____
/ __/_______ __ _______ / __/_______ __ _______
@ -436,6 +443,7 @@ Checking directory permissions...[done]
[•] Output bitrate: 320k [•] Output bitrate: 320k
=============================== ===============================
``` ```
<!-- editorconfig-checker-enable -->
</details> </details>
@ -444,6 +452,7 @@ Checking directory permissions...[done]
<details> <details>
<summary> <code> freyr https://www.deezer.com/us/artist/14808825 </code> </summary> <summary> <code> freyr https://www.deezer.com/us/artist/14808825 </code> </summary>
<!-- editorconfig-checker-disable -->
```console ```console
____ ____
/ __/_______ __ _______ / __/_______ __ _______
@ -503,6 +512,7 @@ Checking directory permissions...[done]
[•] Output bitrate: 320k [•] Output bitrate: 320k
=============================== ===============================
``` ```
<!-- editorconfig-checker-enable -->
</details> </details>
@ -752,7 +762,7 @@ An invalid `refreshToken`, when specified, would fallback to requesting account
- `storefront`: \<string\> - `storefront`: \<string\>
- `developerToken`: \<string\> - `developerToken`: \<string\>
This library already includes a pre-defined developer token that should work at will. This developer token is the default token, extracted off the Apple Music website. While this developer token could expire over time, we'll try to update with the most recent developer token as time goes on. This library already includes a predefined developer token that should work at will. This developer token is the default token, extracted off the Apple Music site. While this developer token could expire over time, we'll try to update with the most recent developer token as time goes on.
To create a custom developer token, please refer to the Apple Music documentation on this topic. To create a custom developer token, please refer to the Apple Music documentation on this topic.
@ -870,7 +880,7 @@ To preview filter rules specification, use the `filter` subcommand.
| [Spotify](https://github.com/miraclx/freyr-js/blob/master/src/services/spotify.js) | ✔ | ✔ | ✔ | ✔ | `spotify:` | | [Spotify](https://github.com/miraclx/freyr-js/blob/master/src/services/spotify.js) | ✔ | ✔ | ✔ | ✔ | `spotify:` |
| [Apple Music](https://github.com/miraclx/freyr-js/blob/master/src/services/apple_music.js) | ✔ | ✔ | ✔ | ✔ | `apple_music:` | | [Apple Music](https://github.com/miraclx/freyr-js/blob/master/src/services/apple_music.js) | ✔ | ✔ | ✔ | ✔ | `apple_music:` |
| [Deezer](https://github.com/miraclx/freyr-js/blob/master/src/services/deezer.js) | ✔ | ✔ | ✔ | ✔ | `deezer:` | | [Deezer](https://github.com/miraclx/freyr-js/blob/master/src/services/deezer.js) | ✔ | ✔ | ✔ | ✔ | `deezer:` |
| Youtube Music (See [#6](https://github.com/miraclx/freyr-js/issues/6)) | ✗ | ✗ | ✗ | ✗ | ✗ | | YouTube Music (See [#6](https://github.com/miraclx/freyr-js/issues/6)) | ✗ | ✗ | ✗ | ✗ | ✗ |
| Tidal (See [#33](https://github.com/miraclx/freyr-js/issues/33)) | ✗ | ✗ | ✗ | ✗ | ✗ | | Tidal (See [#33](https://github.com/miraclx/freyr-js/issues/33)) | ✗ | ✗ | ✗ | ✗ | ✗ |
### Metadata Availability ### Metadata Availability
@ -1082,7 +1092,7 @@ Optionally, you can use these interesting flags to customize the experience.
The freyr source would be available in the `/freyr` directory within the container along with a globally registered command `freyr` for calling the script. The freyr source would be available in the `/freyr` directory within the container along with a globally registered command `freyr` for calling the script.
For more information and documentation about docker, please refer to its official website: For more information and documentation about docker, please refer to its official site:
- <https://www.docker.com/> - <https://www.docker.com/>
- <https://docs.docker.com/> - <https://docs.docker.com/>

View File

@ -51,7 +51,6 @@
}, },
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@babel/eslint-parser": "^7.17.0",
"@miraclx/apple-music": "^0.4.0", "@miraclx/apple-music": "^0.4.0",
"async": "^3.2.0", "async": "^3.2.0",
"axios": "^0.26.0", "axios": "^0.26.0",
@ -90,6 +89,7 @@
"yt-search": "^2.10.3" "yt-search": "^2.10.3"
}, },
"devDependencies": { "devDependencies": {
"@babel/eslint-parser": "^7.17.0",
"eslint": "8.9.0", "eslint": "8.9.0",
"eslint-plugin-prettier": "4.0.0", "eslint-plugin-prettier": "4.0.0",
"prettier": "2.5.1" "prettier": "2.5.1"

View File

@ -70,12 +70,14 @@ function initTest() {
console.log(parseBlock.parsed); console.log(parseBlock.parsed);
values.forEach(value => console.log(`[${value.toString().padStart(2)}] ${parseBlock.check(value)}`)); values.forEach(value => console.log(`[${value.toString().padStart(2)}] ${parseBlock.check(value)}`));
} }
// jscpd:ignore-start
function test_time(spec, values) { function test_time(spec, values) {
console.log('%j', spec); console.log('%j', spec);
const parseBlock = parseRange.time(spec); const parseBlock = parseRange.time(spec);
console.log(parseBlock.parsed); console.log(parseBlock.parsed);
values.forEach(value => console.log(`[${value.toString().padStart(2)}] ${parseBlock.check(value)}`)); values.forEach(value => console.log(`[${value.toString().padStart(2)}] ${parseBlock.check(value)}`));
} }
// jscpd:ignore-end
test_num(' ', [1, 2, 3]); test_num(' ', [1, 2, 3]);
test_num('7 ', [6, 7, 8]); test_num('7 ', [6, 7, 8]);

View File

@ -290,10 +290,10 @@ class AppleMusic {
(await this.getArtist(uris)).albums.map(album => `apple_music:album:${album}`), (await this.getArtist(uris)).albums.map(album => `apple_music:album:${album}`),
100, 100,
store, store,
async (items, storefront) => (items, storefront) =>
Promise.mapSeries( this.getAlbum(
(await this.#store.core.albums.get(`?ids=${items.map(item => item.refID).join(',')}`, {storefront})).data, items.map(item => item.uri),
album => this.wrapAlbumData(album), storefront,
), ),
); );
} }

View File

@ -20,6 +20,18 @@ class YouTubeSearchError extends Error {
} }
} }
function _getSearchArgs(artists, track, duration) {
if (typeof track === 'number') [track, duration] = [, track];
if (!Array.isArray(artists))
if (track && artists) artists = [artists];
else [artists, track] = [[], artists || track];
if (typeof track !== 'string') throw new Error('<track> must be a valid string');
if (artists.some(artist => typeof artist !== 'string'))
throw new Error('<artist>, if defined must be a valid array of strings');
if (duration && typeof duration !== 'number') throw new Error('<duration>, if defined must be a valid number');
return [artists, track, duration];
}
/** /**
* @typedef {( * @typedef {(
* { * {
@ -276,14 +288,7 @@ class YouTubeMusic {
* @returns {YouTubeSearchResult} YouTubeMusicSearchResults * @returns {YouTubeSearchResult} YouTubeMusicSearchResults
*/ */
async search(artists, track, duration) { async search(artists, track, duration) {
if (typeof track === 'number') [track, duration] = [, track]; [artists, track, duration] = _getSearchArgs(artists, track, duration);
if (!Array.isArray(artists))
if (track && artists) artists = [artists];
else [artists, track] = [[], artists || track];
if (typeof track !== 'string') throw new Error('<track> must be a valid string');
if (artists.some(artist => typeof artist !== 'string'))
throw new Error('<artist>, if defined must be a valid array of strings');
if (duration && typeof duration !== 'number') throw new Error('<duration>, if defined must be a valid number');
const results = await this.#search({query: [track, ...artists].join(' ')}); const results = await this.#search({query: [track, ...artists].join(' ')});
const strippedMeta = textUtils.stripText([...track.split(' '), ...artists]); const strippedMeta = textUtils.stripText([...track.split(' '), ...artists]);
@ -384,14 +389,7 @@ class YouTube {
* @returns {YouTubeSearchResult} YouTubeSearchResults * @returns {YouTubeSearchResult} YouTubeSearchResults
*/ */
async search(artists, track, duration) { async search(artists, track, duration) {
if (typeof track === 'number') [track, duration] = [, track]; [artists, track, duration] = _getSearchArgs(artists, track, duration);
if (!Array.isArray(artists))
if (track && artists) artists = [artists];
else [artists, track] = [[], artists || track];
if (typeof track !== 'string') throw new Error('<track> must be a valid string');
if (artists.some(artist => typeof artist !== 'string'))
throw new Error('<artist>, if defined must be a valid array of strings');
if (duration && typeof duration !== 'number') throw new Error('<duration>, if defined must be a valid number');
const strippedArtists = textUtils.stripText(artists); const strippedArtists = textUtils.stripText(artists);
const strippedMeta = [...textUtils.stripText(track.split(' ')), ...strippedArtists]; const strippedMeta = [...textUtils.stripText(track.split(' ')), ...strippedArtists];

View File

@ -182,8 +182,7 @@ class StackLogger {
* @param {...any} msgs Messages to write out * @param {...any} msgs Messages to write out
*/ */
error(...msgs) { error(...msgs) {
this._write(this.getText(this.#store.indent, msgs).concat('\n'), process.stderr, true); return this.warn(...msgs);
return this.#store.autoTick ? this.tick(this.#store.indentSize) : this;
} }
/** /**