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

feature: setup linting #13

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
37 changes: 37 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"requireConfigFile": false
},
"env": {
"browser": true,
"es6": true,
"node": true,
"jest": true
},
"rules": {
"no-var": "error",
"prefer-const": "warn",
"no-console": "off",
"no-debugger": "warn",
"no-undef": "error",
"no-unused-vars": "warn",
"quotes": ["warn", "single"],
"semi": ["error", "never"],
"new-cap": 2,
"no-caller": 2,
"dot-notation": 0,
"no-eq-null": 2,
"no-unused-expressions": 0,
"curly": 0,
"eqeqeq": 2,
"wrap-iife": [2, "any"],
"no-use-before-define": [
2,
{
"functions": false
}
]
}
}
23 changes: 15 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
name: CI

on:
pull_request:
branches:
- main
push:
branches:
- main
pull_request:

jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Checkout
uses: actions/checkout@v4

- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: 18
- run: |
npm install
npm run test:unit

- name: Install dependencies
run: npm install --frozen-lockfile

- name: Lint
run: npm run lint

- name: Unit Test
run: npm run test:unit
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 120,
"tabWidth": 4,
"semi": false,
"bracketSpacing": true,
"proseWrap": "always",
"arrowParens": "always",
"htmlWhitespaceSensitivity": "css"
}
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
presets: ['@babel/preset-env'],
plugins: ['babel-plugin-transform-import-meta']
plugins: ['babel-plugin-transform-import-meta'],
}
93 changes: 52 additions & 41 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,72 @@
const gulp = require('gulp')
const {rollup} = require('rollup')
const eslint = require('gulp-eslint')
const prettier = require('gulp-prettier')
const { rollup } = require('rollup')
const terser = require('@rollup/plugin-terser')
const babel = require('@rollup/plugin-babel').default
const commonjs = require('@rollup/plugin-commonjs')
const resolve = require('@rollup/plugin-node-resolve').default

let cache = {}
const cache = {}

const babelConfig = {
babelHelpers: 'bundled',
ignore: ['node_modules'],
compact: false,
extensions: ['.js', '.html'],
plugins: [
'transform-html-import-to-string'
plugins: ['transform-html-import-to-string'],
presets: [
[
'@babel/preset-env',
{
corejs: 3,
useBuiltIns: 'usage',
modules: false,
},
],
],
presets: [[
'@babel/preset-env',
{
corejs: 3,
useBuiltIns: 'usage',
modules: false
}
]],
configFile: false
configFile: false,
}

gulp.task('lint', () =>
gulp.src(['./**/*.js', '!node_modules/**', '!plugin/awesoMD/awesoMD*.js']).pipe(eslint()).pipe(eslint.format())
)

gulp.task('format', () =>
gulp.src(['./**/*.js', '!node_modules/**', '!plugin/awesoMD/awesoMD*.js']).pipe(prettier()).pipe(gulp.dest('.'))
)

gulp.task('build-plugins', () => {
return Promise.all([
{ name: 'RevealAwesoMD', input: './plugin/awesoMD/plugin.js', output: './plugin/awesoMD/awesoMD' },
].map( plugin => {
return rollup({
cache: cache[plugin.input],
input: plugin.input,
plugins: [
resolve(),
commonjs(),
babel({
...babelConfig,
ignore: ["node_modules"],
}),
terser()
]
}).then( bundle => {
cache[plugin.input] = bundle.cache;
bundle.write({
file: plugin.output + '.esm.js',
name: plugin.name,
format: 'es'
})
return Promise.all(
[{ name: 'RevealAwesoMD', input: './plugin/awesoMD/plugin.js', output: './plugin/awesoMD/awesoMD' }].map(
(plugin) => {
return rollup({
cache: cache[plugin.input],
input: plugin.input,
plugins: [
resolve(),
commonjs(),
babel({
...babelConfig,
ignore: ['node_modules'],
}),
terser(),
],
}).then((bundle) => {
cache[plugin.input] = bundle.cache
bundle.write({
file: plugin.output + '.esm.js',
name: plugin.name,
format: 'es',
})

bundle.write({
file: plugin.output + '.js',
name: plugin.name,
format: 'umd'
bundle.write({
file: plugin.output + '.js',
name: plugin.name,
format: 'umd',
})
})
});
} ));
}
)
)
})
12 changes: 6 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = {
testEnvironment: "node",
testMatch: ["**/__tests__/**/*.js", "**/?(*.)+(spec|test).js"],
moduleFileExtensions: ["js", "json", "jsx", "node"],
testEnvironment: 'node',
testMatch: ['**/__tests__/**/*.js', '**/?(*.)+(spec|test).js'],
moduleFileExtensions: ['js', 'json', 'jsx', 'node'],
collectCoverage: true,
verbose: true,
transform: {
"\\.[j]sx?$": "babel-jest",
}
};
'\\.[j]sx?$': 'babel-jest',
},
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"description": "Revealjs plugin to support markdown with metadata and templates",
"scripts": {
"build": "gulp build-plugins",
"test:unit": "jest"
"test:unit": "jest",
"lint": "gulp lint",
"lint:fix": "gulp format"
},
"repository": {
"type": "git",
Expand All @@ -30,6 +32,8 @@
"core-js": "^3.36.1",
"front-matter": "^4.0.2",
"gulp": "^5.0.0",
"gulp-eslint": "^6.0.0",
"gulp-prettier": "^5.0.0",
"jest": "^29.7.0",
"js-yaml": "^4.1.0",
"marked": "^4.3.0",
Expand Down
Loading
Loading