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

This is a fake PR to test GH actions #2421

Closed
Closed
Show file tree
Hide file tree
Changes from 4 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
45 changes: 45 additions & 0 deletions .github/workflows/lint-and-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Lint and Format Code Base

on:
pull_request:
paths:
- 'src/**/*.js'

jobs:
lint_and_format:
name: runner / eslint and prettier
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write

steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Important to fetch all history for diff

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install dependencies
run: npm install

- name: Run ESLint with reviewdog
uses: reviewdog/action-eslint@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-review
eslint_flags: 'src'
filter_mode: 'diff_context'

- name: Run Prettier with reviewdog
uses: EPMatt/reviewdog-action-prettier@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-review
prettier_flags: '--check src/**/*.js'
filter_mode: 'diff_context'

114 changes: 114 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { FlatCompat } from "@eslint/eslintrc";
import pluginJs from "@eslint/js";
import path from "path";
import { fileURLToPath } from "url";
import globals from "globals";
import prettierConfig from "eslint-config-prettier";
import requirejs from "eslint-plugin-requirejs";
import jsdoc from "eslint-plugin-jsdoc";

// For compatibility with configs that don't use the new eslint flat config format:
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
});

// ---------------------------------------------------------------------
// ESLINT RECOMMENDED:
// Use the recommended config for JS files by eslint
const eslintRecommendedConfig = pluginJs.configs.recommended;
const eslintRulesOverrides = {
// Allow underscored names to explicitly indicate an argument is not used
"no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
};

// ---------------------------------------------------------------------
// AIRBNB JAVASCRIPT STYLE GUIDE:
// Use the Airbnb style guide, excluding react- and node- specific rules & the
// rule that disallows "use strict"
const airbnbConfigs = [
...compat.extends("eslint-config-airbnb-base/rules/best-practices"),
...compat.extends("eslint-config-airbnb-base/rules/errors"),
...compat.extends("eslint-config-airbnb-base/rules/style"),
...compat.extends("eslint-config-airbnb-base/rules/variables"),
...compat.extends("eslint-config-airbnb-base/rules/es6"),
...compat.extends("eslint-config-airbnb-base/rules/imports"),
];
const airbnbRulesOverrides = {
// We are using the AMD/RequireJS module pattern
"import/no-amd": "off",
"import/no-commonjs": "off",
};

// ---------------------------------------------------------------------
// JSDOCS:
// Ensure JSDoc comments are used, and check validity
const jsdocConfig = jsdoc.configs["flat/recommended"];
const jsdocsRulesOverrides = {
// Non-standard JSDoc tags we use to generate documentation.
"jsdoc/check-tag-names": [
"error",
{ definedTags: ["classcategory", "screenshot"] },
],
// Avoiding this error would mean importing modules we don't use
"jsdoc/no-undefined-types": "off",
};

// ---------------------------------------------------------------------
// REQUIREJS
// Use all rules from the recommended config for RequireJS
const requirejsConfig = {
name: "requirejs",
plugins: {
requirejs,
},
rules: {
...requirejs.configs.recommended.rules,
},
};

// ---------------------------------------------------------------------
// METACATUI OVERRIDES
const metacatuiConfig = {
files: ["src/**/*.js"],
languageOptions: {
sourceType: "commonjs",
ecmaVersion: 2020,
globals: {
...globals.browser,
...globals.amd,
MetacatUI: "readonly",
google: "readonly",
},
},
// Override rules that are not compatible with MetacatUI
rules: {
...eslintRulesOverrides,
...airbnbRulesOverrides,
...jsdocsRulesOverrides,
},
};

// Ignores must be a separate object to be treated as global
const ignoreList = {
ignores: [
"src/components/",
"docs/",
"test/",
"node_modules/",
".github",
"server.js",
"eslint.config.mjs",
],
};

export default [
ignoreList,
eslintRecommendedConfig,
...airbnbConfigs,
jsdocConfig,
requirejsConfig,
metacatuiConfig,
prettierConfig, // prettier must be the last config in the array
];
Loading
Loading