From 7bfff4d42e819a7fbdc0e14e1c9ebd31a42372a3 Mon Sep 17 00:00:00 2001 From: Vicary Date: Fri, 16 Dec 2022 12:10:21 +0800 Subject: [PATCH] feat(eslint): support yml and expand lint scope --- .eslintrc.yml | 52 +++++----- .github/workflows/lint.yml | 10 +- .../first.js | 7 +- .../second.js | 7 +- .../handler.js | 3 +- .../include-external-npm-packages/handler.js | 3 +- package-lock.json | 94 +++++++++++++++++++ package.json | 3 +- 8 files changed, 144 insertions(+), 35 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 5e4560c79..449b93417 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -11,7 +11,12 @@ extends: - plugin:import/errors - plugin:import/warnings - prettier -parser: "@babel/eslint-parser" +overrides: + - files: + - '*.yml' + - '*.yaml' + parser: 'yaml-eslint-parser' +parser: '@babel/eslint-parser' parserOptions: requireConfigFile: false sourceType: module @@ -20,36 +25,41 @@ plugins: - lodash - import - prettier + - yml rules: - linebreak-style: [ error, unix ] - semi: [ error, always ] - quotes: [ error, single, { avoidEscape: true } ] + linebreak-style: [error, unix] + semi: [error, always] + quotes: [error, single, { avoidEscape: true }] no-mixed-spaces-and-tabs: error space-before-blocks: error arrow-spacing: error - key-spacing: [ error, { afterColon: true, mode: minimum } ] - brace-style: [ error, '1tbs' ] - comma-spacing: [ error, { before: false, after: true } ] - comma-style: [ error, last, { exceptions: { VariableDeclaration: true } } ] - computed-property-spacing: [ error, never ] - object-curly-spacing: [ error, always ] + key-spacing: [error, { afterColon: true, mode: minimum }] + brace-style: [error, '1tbs'] + comma-spacing: [error, { before: false, after: true }] + comma-style: [error, last, { exceptions: { VariableDeclaration: true } }] + computed-property-spacing: [error, never] + object-curly-spacing: [error, always] prefer-const: error no-var: error promise/no-nesting: off import/first: error import/newline-after-import: error import/no-named-as-default: off - import/no-extraneous-dependencies: [ error, { devDependencies: true } ] + import/no-extraneous-dependencies: [error, { devDependencies: true }] lodash/import-scope: off lodash/preferred-alias: off lodash/prop-shorthand: off - lodash/prefer-lodash-method: [ error, { ignoreObjects: [ BbPromise, path ] } ] - max-len: [ error, { code: 120, ignoreStrings: true, ignoreComments: true, ignoreTemplateLiterals: true } ] - prettier/prettier: [ error, { - printWidth: 120, - arrowParens: 'avoid', - bracketSpacing: true, - semi: true, - singleQuote: true, - trailingComma: 'none', - } ] + lodash/prefer-lodash-method: [error, { ignoreObjects: [BbPromise, path] }] + max-len: [error, { code: 120, ignoreStrings: true, ignoreComments: true, ignoreTemplateLiterals: true }] + prettier/prettier: + [ + error, + { + printWidth: 120, + arrowParens: 'avoid', + bracketSpacing: true, + semi: true, + singleQuote: true, + trailingComma: 'none' + } + ] diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 76ff11f1d..d1069492a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,17 +17,17 @@ jobs: steps: - name: "Checkout" - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: - fetch-depth: 2 + fetch-depth: 0 - name: "Install Node.js" - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: - node-version: "12" + node-version: 16 - name: "Install dependencies" run: npm ci - name: "Lint files" - run: "npm run eslint" + run: "npm run eslint -- --ignore-pattern examples/" diff --git a/examples/babel-multiple-statically-entries/first.js b/examples/babel-multiple-statically-entries/first.js index b6be064f4..8fa0419e4 100644 --- a/examples/babel-multiple-statically-entries/first.js +++ b/examples/babel-multiple-statically-entries/first.js @@ -1,8 +1,9 @@ -export const hello = (event, context, cb) => { - const p = new Promise((resolve, reject) => { +/* eslint-disable promise/no-callback-in-promise */ +export const hello = (event, _, cb) => { + const p = new Promise(resolve => { resolve('success'); }); - p.then(r => + p.then(() => cb(null, { message: 'Go Serverless Webpack (Babel) v1.0! First module!', event diff --git a/examples/babel-multiple-statically-entries/second.js b/examples/babel-multiple-statically-entries/second.js index ac76a34ad..f2c31f3fe 100644 --- a/examples/babel-multiple-statically-entries/second.js +++ b/examples/babel-multiple-statically-entries/second.js @@ -1,8 +1,9 @@ -export const hello = (event, context, cb) => { - const p = new Promise((resolve, reject) => { +/* eslint-disable promise/no-callback-in-promise */ +export const hello = (event, _, cb) => { + const p = new Promise(resolve => { resolve('success'); }); - p.then(r => + p.then(() => cb(null, { message: 'Go Serverless Webpack (Babel) v1.0! Second module!', event diff --git a/examples/include-external-npm-packages-lock-file/handler.js b/examples/include-external-npm-packages-lock-file/handler.js index 17621c6ae..af7f265ba 100644 --- a/examples/include-external-npm-packages-lock-file/handler.js +++ b/examples/include-external-npm-packages-lock-file/handler.js @@ -1,6 +1,7 @@ // Should keep side-effects scripts import 'dotenv/config'; // Should be included as fbgraph is not marked as sideEffect free +// eslint-disable-next-line no-unused-vars import { fbgraph } from 'fbgraph'; // Should keep named imports import { toUpper } from 'lodash'; @@ -11,7 +12,7 @@ function getMessage() { return isEqual(true, false) ? 'noop' : toUpper('hello fb & aws'); } -export const hello = function (event, context, cb) { +export const hello = function (event, _, cb) { const message = getMessage(); cb(null, { message, event }); }; diff --git a/examples/include-external-npm-packages/handler.js b/examples/include-external-npm-packages/handler.js index e37d2c604..8632f25e1 100644 --- a/examples/include-external-npm-packages/handler.js +++ b/examples/include-external-npm-packages/handler.js @@ -1,8 +1,9 @@ +/* eslint-disable no-unused-vars */ 'use strict'; const AWS = require('aws-sdk'); const fbgraph = require('fbgraph'); -module.exports.hello = function (event, context, cb) { +module.exports.hello = function (event, _, cb) { cb(null, { message: 'hello fb & aws', event }); }; diff --git a/package-lock.json b/package-lock.json index 6e2fb68f9..0127d5151 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,6 +30,7 @@ "eslint-plugin-lodash": "^7.4.0", "eslint-plugin-prettier": "^4.2.1", "eslint-plugin-promise": "^6.1.1", + "eslint-plugin-yml": "^1.3.0", "husky": "^4.3.8", "jest": "^27.5.1", "lint-staged": "^10.5.4", @@ -5235,6 +5236,27 @@ "eslint": "^7.0.0 || ^8.0.0" } }, + "node_modules/eslint-plugin-yml": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-yml/-/eslint-plugin-yml-1.3.0.tgz", + "integrity": "sha512-TEkIaxutVPRZMRc0zOVptP/vmrf1td/9woUAiKII4kRLJLWWUCz1CYM98NsAfeOrVejFBFhHCSwOp+C1TqmtRg==", + "dev": true, + "dependencies": { + "debug": "^4.3.2", + "lodash": "^4.17.21", + "natural-compare": "^1.4.0", + "yaml-eslint-parser": "^1.1.0" + }, + "engines": { + "node": "^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ota-meshi" + }, + "peerDependencies": { + "eslint": ">=6.0.0" + } + }, "node_modules/eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -14194,6 +14216,41 @@ "integrity": "sha512-2PTINUwsRqSd+s8XxKaJWQlUuEMHJQyEuh2edBbW8KNJz0SJPwUSD2zRWqezFEdN7IzAgeuYHFUCF7o8zRdZ0A==", "dev": true }, + "node_modules/yaml-eslint-parser": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/yaml-eslint-parser/-/yaml-eslint-parser-1.1.0.tgz", + "integrity": "sha512-b464Q1fYiX1oYx2kE8k4mEp6S9Prk+tfDsY/IPxQ0FCjEuj3AKko5Skf3/yQJeYTTDyjDE+aWIJemnv29HvEWQ==", + "dev": true, + "dependencies": { + "eslint-visitor-keys": "^3.0.0", + "lodash": "^4.17.21", + "yaml": "^2.0.0" + }, + "engines": { + "node": "^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ota-meshi" + } + }, + "node_modules/yaml-eslint-parser/node_modules/eslint-visitor-keys": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz", + "integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==", + "dev": true, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/yaml-eslint-parser/node_modules/yaml": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.1.3.tgz", + "integrity": "sha512-AacA8nRULjKMX2DvWvOAdBZMOfQlypSFkjcOcu9FalllIDJ1kvlREzcdIZmidQUqqeMv7jorHjq2HlLv/+c2lg==", + "dev": true, + "engines": { + "node": ">= 14" + } + }, "node_modules/yamljs": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/yamljs/-/yamljs-0.3.0.tgz", @@ -18581,6 +18638,18 @@ "dev": true, "requires": {} }, + "eslint-plugin-yml": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-yml/-/eslint-plugin-yml-1.3.0.tgz", + "integrity": "sha512-TEkIaxutVPRZMRc0zOVptP/vmrf1td/9woUAiKII4kRLJLWWUCz1CYM98NsAfeOrVejFBFhHCSwOp+C1TqmtRg==", + "dev": true, + "requires": { + "debug": "^4.3.2", + "lodash": "^4.17.21", + "natural-compare": "^1.4.0", + "yaml-eslint-parser": "^1.1.0" + } + }, "eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -25139,6 +25208,31 @@ "integrity": "sha512-2PTINUwsRqSd+s8XxKaJWQlUuEMHJQyEuh2edBbW8KNJz0SJPwUSD2zRWqezFEdN7IzAgeuYHFUCF7o8zRdZ0A==", "dev": true }, + "yaml-eslint-parser": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/yaml-eslint-parser/-/yaml-eslint-parser-1.1.0.tgz", + "integrity": "sha512-b464Q1fYiX1oYx2kE8k4mEp6S9Prk+tfDsY/IPxQ0FCjEuj3AKko5Skf3/yQJeYTTDyjDE+aWIJemnv29HvEWQ==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^3.0.0", + "lodash": "^4.17.21", + "yaml": "^2.0.0" + }, + "dependencies": { + "eslint-visitor-keys": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz", + "integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==", + "dev": true + }, + "yaml": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.1.3.tgz", + "integrity": "sha512-AacA8nRULjKMX2DvWvOAdBZMOfQlypSFkjcOcu9FalllIDJ1kvlREzcdIZmidQUqqeMv7jorHjq2HlLv/+c2lg==", + "dev": true + } + } + }, "yamljs": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/yamljs/-/yamljs-0.3.0.tgz", diff --git a/package.json b/package.json index 7e9ba9ab0..b98515864 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "scripts": { "test": "jest --verbose", "test-coverage": "jest --coverage", - "eslint": "eslint --ext .js *.js lib tests" + "eslint": "eslint ." }, "dependencies": { "archiver": "^5.3.1", @@ -54,6 +54,7 @@ "eslint-plugin-lodash": "^7.4.0", "eslint-plugin-prettier": "^4.2.1", "eslint-plugin-promise": "^6.1.1", + "eslint-plugin-yml": "^1.3.0", "husky": "^4.3.8", "jest": "^27.5.1", "lint-staged": "^10.5.4",