Skip to content

Commit

Permalink
Merge branch 'lint/eslint-all' into feature/feedback-button
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Jan 3, 2024
2 parents 07ba509 + a8fc972 commit 47b7cc6
Show file tree
Hide file tree
Showing 553 changed files with 8,507 additions and 8,072 deletions.
87 changes: 87 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Starting with v9, this config will be deprecated in favor of the new
// configuration files [1]. @stylistic is already ready for the new "flat config",
// when it's time, copy the new config from [2].
// [1] https://eslint.org/docs/latest/use/configure/configuration-files-new
// [2] https://eslint.style/guide/config-presets#configuration-factory

// Stylistic Plugin for ESLint
// see the rules in [3] and [4].
// [3] https://eslint.style/packages/js#rules
// [4] https://eslint.org/docs/rules/
const stylistic = require("@stylistic/eslint-plugin");

const customizedStylistic = stylistic.configs.customize({
"indent": 2,
"jsx": false,
"quote-props": "always",
"semi": "always",
"brace-style": "1tbs",
});

const cypressRules = {
"cypress/no-assigning-return-values": "error",
"cypress/no-unnecessary-waiting": "off", // TODO: fix this issue
"cypress/assertion-before-screenshot": "warn",
"cypress/no-force": "warn",
"cypress/no-async-tests": "error",
"cypress/no-pause": "error",
};

const ignoreFilesWithSprocketRequireSyntax = [
"app/assets/javascripts/application.js",
"app/assets/config/manifest.js",
"app/assets/javascripts/edit_clicker_assets.js",
"app/assets/javascripts/show_clicker_assets.js",
"app/assets/javascripts/geogebra_assets.js",
"vendor/assets/javascripts/thredded_timeago.js",
];

const customGlobals = {
TomSelect: "readable",
bootstrap: "readable",

// Rails globals
Routes: "readable",
App: "readable",
ActionCable: "readable",

// Common global methods
initBootstrapPopovers: "readable",
};

module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2022,
sourceType: "module",
},
env: {
"node": true,
"browser": true,
"jquery": true,
"cypress/globals": true,
},
extends: [
"eslint:recommended",
// Allow linting of ERB files, see https://github.com/Splines/eslint-plugin-erb
"plugin:erb/recommended",
],
globals: customGlobals,
plugins: ["@stylistic", "erb", "cypress"],
rules: {
...customizedStylistic.rules,
"no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
...cypressRules,
// see https://github.com/eslint-stylistic/eslint-stylistic/issues/254
"@stylistic/quotes": ["error", "double", { avoidEscape: true }],
},
ignorePatterns: [
"node_modules/",
"pdfcomprezzor/",
"tmp/",
"public/packs/",
"public/packs-test/",
"public/uploads/",
...ignoreFilesWithSprocketRequireSyntax,
],
};
11 changes: 0 additions & 11 deletions .eslintrc.json

This file was deleted.

42 changes: 42 additions & 0 deletions .github/actions/changed_files/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Why is this file in a subdirectory? Because GitHub Actions requires it to be :(
# see: https://github.com/orgs/community/discussions/26245#discussioncomment-5962450
name: "Get changed files"
description: "Checks out the code and returns the filenames of files that have changed in the pull request"

inputs:
file-extensions:
# for example: "\.rb$" or something like "\.js$|\.js.erb$"
description: "Regex expressions for grep to filter for specific files"
required: true

outputs:
changed-files:
description: "A space-separated list of the files that have changed in the pull request"
value: ${{ steps.get-changed-files.outputs.files }}

runs:
using: "composite"
steps:
# This has to be done in the main workflow, not in the action, because
# otherwise this reusable action is not available in the workflow.
# - name: "Checkout code (on a PR branch)"
# uses: actions/checkout@v4
# with:
# fetch-depth: 2 # to also fetch parent of PR

# Adapted from this great comment [1]. Git diff adapted from [2].
# "|| test $? = 1;" is used to ignore the exit code of grep when no files
# are found matching the pattern. For the "three dots" ... syntax, see [3].
#
# Resources:
# number [1] being most important
# [1] https://github.com/actions/checkout/issues/520#issuecomment-1167205721
# [2] https://robertfaldo.medium.com/commands-to-run-rubocop-and-specs-you-changed-in-your-branch-e6d2f2e4110b
# [3] https://community.atlassian.com/t5/Bitbucket-questions/Git-diff-show-different-files-than-PR-Pull-Request/qaq-p/2331786
- name: Get changed files
shell: bash
id: get-changed-files
run: |
files_pretty=$(git diff --name-only --diff-filter=ACMR -r HEAD^1...HEAD | egrep '${{inputs.file-extensions}}' || test $? = 1;)
printf "🎴 Changed files: \n$files_pretty"
echo "files=$(echo ${files_pretty} | xargs)" >> $GITHUB_OUTPUT
134 changes: 58 additions & 76 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,87 +1,69 @@
on: [push]
name: Linting

# Trigger each time HEAD branch is updated in a pull request
# see https://github.com/orgs/community/discussions/26366
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]

jobs:

rubocop:
name: RuboCop (Ruby)
runs-on: ubuntu-latest
name: A job to check rubocop linter errors
steps:
- uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2 # to also fetch parent of PR (used to get changed files)

- name: Get changed files
id: rb-changed
uses: ./.github/actions/changed_files/
with:
file-extensions: \.rb$

- name: Set up Ruby 3
if: ${{ steps.rb-changed.outputs.changed-files != ''}}
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.4
- name: Install gems # usual step to install the gems.
bundler-cache: true

- name: Run RuboCop
if: ${{ steps.rb-changed.outputs.changed-files != ''}}
run: |
bin/bundle config path vendor/bundle
bin/bundle config set without 'default doc job cable storage ujs test db'
bin/bundle install --jobs 4 --retry 3
- name: Linter count
id: hello
uses: henrixapp/linter-less-or-equal-action@v1.19
with:
name: Rubocop
command: bin/bundle exec rubocop app config lib spec
total_regexp: \d+ offenses detected
errors_regexp: \d+ offenses detected
warnings_regexp: \d+ offenses detected
compare_branch: mampf-next
mode: changed
include: .rb
echo "🚨 Running RuboCop version: $(bundle info rubocop | head -1)"
bundle exec rubocop --format github --fail-level 'convention' --force-exclusion -- $CHANGED_FILES
eslint:
runs-on: ubuntu-latest
name: A job to check eslint linter errors
steps:
- uses: actions/checkout@v2
- name: Linter count
id: hello
uses: henrixapp/linter-less-or-equal-action@v1.19
with:
name: EsLint
command: npx eslint
total_regexp: \d+ problems
errors_regexp: \d+ errors
warnings_regexp: \d+ warnings
compare_branch: mampf-next
mode: changed
include: .js
coffee:
runs-on: ubuntu-latest
name: A job to check coffee linter errors
steps:
- uses: actions/checkout@v2
- name: Linter count
id: hello
uses: henrixapp/linter-less-or-equal-action@v1.19
with:
name: Coffee
command: npx coffeelint
total_regexp: \d+ errors
errors_regexp: \d+ errors
warnings_regexp: \d+ warnings
compare_branch: mampf-next
mode: changed
include: .coffee
# erblint:
# runs-on: ubuntu-latest
# name: A job to check erblint linter errors
# steps:
# - uses: actions/checkout@v2
# - name: Set up Ruby 2.7
# uses: ruby/setup-ruby@v1
# with:
# ruby-version: 2.7
# - name: Install gems # usual step to install the gems.
# run: |
# bin/bundle config path vendor/bundle
# bin/bundle config set without 'default doc job cable storage ujs test db'
# bin/bundle install --jobs 4 --retry 3
# - name: Linter count
# id: hello
# uses: henrixapp/linter-less-or-equal-action@v1.1
# with:
# name: Erblint
# command: bin/bundle exec erblint .
# total_regexp: \d+ error(s)
# errors_regexp: \d+ error(s)
# warnings_regexp: \d+ error(s)
# compare_branch: mampf-next
name: ESLint (JS)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2 # to also fetch parent of PR (used to get changed files)

- name: Get changed files
id: js-changed
uses: ./.github/actions/changed_files/
with:
file-extensions: \.js$|\.js.erb$

- name: Setup Node.js
if: ${{ steps.js-changed.outputs.changed-files != ''}}
uses: actions/setup-node@v4
with:
node-version: '20' # End of Life (EOL): April 2026
cache: 'yarn'

- name: Install dependencies
if: ${{ steps.js-changed.outputs.changed-files != ''}}
run: yarn install

- name: Run ESLint
if: ${{ steps.js-changed.outputs.changed-files != ''}}
run: |
echo "🚨 Running ESLint version: $(yarn run --silent eslint --version)"
yarn run eslint --ignore-path .gitignore --max-warnings 0 ${{ steps.js-changed.outputs.changed-files }}
84 changes: 0 additions & 84 deletions .github/workflows/tests.yml

This file was deleted.

Loading

0 comments on commit 47b7cc6

Please sign in to comment.