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

Linting SVG files #1642

Merged
merged 22 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 21 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
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ coverage
lib
tests
node_modules
.eslintrc.js
docs/images
docs/guide/basics/examples
packages/lucide-react/dynamicIconImports.js
41 changes: 40 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const DEFAULT_ATTRS = require('./scripts/render/default-attrs.json');

module.exports = {
root: true,
env: {
browser: true,
node: true,
},
extends: ['airbnb-base', 'prettier'],
plugins: ['import', 'prettier'],
plugins: ['import', 'prettier', '@html-eslint'],
rules: {
'no-console': 'off',
'no-param-reassign': 'off',
Expand All @@ -15,6 +18,7 @@ module.exports = {
{
singleQuote: true,
trailingComma: 'all',
printWidth: 100
},
],
'import/no-extraneous-dependencies': [
Expand All @@ -37,4 +41,39 @@ module.exports = {
ecmaVersion: 'latest',
sourceType: 'module',
},
overrides: [
{
files: ['./icons/*.svg'],
parser: '@html-eslint/parser',
rules: {
'prettier/prettier': 'off',
'@html-eslint/require-doctype': 'off',
'@html-eslint/no-duplicate-attrs': 'error',
'@html-eslint/no-inline-styles': 'error',
'@html-eslint/require-attrs': [
'error',
...Object.entries(DEFAULT_ATTRS)
.map(([attr, value]) => ({ tag: 'svg', attr, value: String(value) }))
],
'@html-eslint/indent': ['error', 2],
"@html-eslint/no-multiple-empty-lines": ["error", { "max": 0 }],
'@html-eslint/no-extra-spacing-attrs': [
'error',
{
enforceBeforeSelfClose: true,
},
],
'@html-eslint/require-closing-tags': [
'error',
{
selfClosing: 'always',
allowSelfClosingCustom: true,
},
],
'@html-eslint/element-newline': 'error',
'@html-eslint/no-trailing-spaces': 'error',
'@html-eslint/quotes': 'error',
}
},
],
};
25 changes: 25 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Linting

on:
pull_request:
paths:
- icons/**

jobs:
linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/[email protected]
with:
node-version: 18
cache: 'pnpm'

- name: Install Dependencies
run: pnpm install --frozen-lockfile

- name: Run Linter
run: pnpm lint
5 changes: 3 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ jobs:
# Example for the previous substitution
# input: +++ b/icons/accessibility.json%0A@@ -2,0 +3 @@%0A+ "contributors": ["hi"],%0A@@ -13 +14 @@%0A+}%0A
# output: ::$ANNOTATION_SEVERITY file=icons/accessibility.json,line=2,endLine=3,title=$ANNOTATION_TITLE::$ANNOTATION_DESCRIPTION%0A%0A+ "contributors": ["hi"],%0A@@ -13 +14 @@%0A+}%0A
- name: Fail if contributors have changed
run: git diff --exit-code -- icons/*.json
# - name: Fail if contributors have changed
# run: git diff --exit-code -- icons/*.json

add-changed-icons-comment:
runs-on: ubuntu-latest
permissions:
Expand Down
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
"preact",
"Preact"
],
"eslint.enable": true,
"eslint.validate": [
"javascript",
"svg"
],
"svg.preview.background": "transparent"
}
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,22 @@
"generate:contributors": "node ./scripts/updateContributors.mjs icons/*.svg",
"generate:nextJSAliases": "node ./scripts/generateNextJSAliases.mjs",
"postinstall": "husky install",
"lint:js": "eslint --ext .ts,.js,.mjs ./{packages/lucide,scripts}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the :js name does not make sense anymore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, i've renamed it to lint:es 😛

"lint:js": "eslint .",
"lint:json:icons": "ajv --spec=draft2020 -s icon.schema.json -d 'icons/*.json' > /dev/null",
"lint:json:categories": "ajv --spec=draft2020 -s category.schema.json -d 'categories/*.json' > /dev/null",
"lint:json": "pnpm run lint:json:icons && pnpm run lint:json:categories",
"lint": "pnpm lint:js lint:json",
"lint": "pnpm lint:js && pnpm lint:json",
"prepare": "husky install",
"gi": "node ./scripts/generate/generateIcons.mjs"
},
"devDependencies": {
"@html-eslint/eslint-plugin": "^0.19.1",
"@html-eslint/parser": "^0.19.1",
"@octokit/rest": "^19.0.13",
"ajv-cli": "^5.0.0",
"eslint": "^8.43.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.3",
"lint-staged": "^13.2.3",
Expand All @@ -54,7 +55,14 @@
"semver": "^7.5.2",
"simple-git": "^3.19.1",
"svgo": "^3.0.2",
"svgson": "^5.2.1"
"svgson": "^5.2.1",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-import-resolver-custom-alias": "^1.3.2",
"eslint-import-resolver-typescript": "^3.6.0",
"eslint-plugin-import": "^2.28.0"
},
"lint-staged": {
"icons/*.svg": [
Expand Down
2 changes: 1 addition & 1 deletion packages/lucide-angular/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies, global-require, func-names */
/* eslint-disable global-require, func-names */
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
process.env.CHROME_BIN = require('puppeteer').executablePath();
Expand Down
4 changes: 2 additions & 2 deletions packages/lucide-vue/nuxt.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join } from 'path';

export default function() {
this.nuxt.hook('components:dirs', dirs => {
export default function LucideNuxtPlugin() {
this.nuxt.hook('components:dirs', (dirs) => {
dirs.push({
path: join(__dirname, 'dist', 'esm', 'icons'),
prefix: 'Icon',
Expand Down
2 changes: 1 addition & 1 deletion packages/lucide-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"build": "pnpm clean && pnpm copy:license && pnpm build:icons && pnpm build:bundles",
"copy:license": "cp ../../LICENSE ./LICENSE",
"clean": "rm -rf dist && rm -rf stats && rm -rf ./src/icons/*.js",
"build:icons": "build-icons --output=./src --templateSrc=./scripts/exportTemplate.mjs --renderUniqueKey --withAliases --aliasesFileExtension=.ts --iconFileExtention=.ts --exportFileName=index.ts",
"build:icons": "build-icons --output=./src --templateSrc=./scripts/exportTemplate.mjs --renderUniqueKey --withAliases --aliasesFileExtension=.ts --iconFileExtension=.ts --exportFileName=index.ts",
"build:bundles": "rollup -c ./rollup.config.mjs",
"test": "vitest run",
"version": "pnpm version --git-tag-version=false"
Expand Down
Loading