-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Provide a clearly defined set of icons under the path "@icons/material". The import of icons from that path is enforced by a custom linter rule. * add named path @iCons to tsconfig and webpack config * add custom rules for material icon imports * create eslint plugin in new lib directory and add it to eslintrc * add eslint-plugin-schulcloud to dockerfile * apply new material import rule, add missing icons * remove prefix 'mdiCustom' for custom icons * replace '$mdi', import material icons from '@icons/material' --------- Co-authored-by: Uwe Ilgenstein <[email protected]>
- Loading branch information
Showing
164 changed files
with
614 additions
and
296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const materialIconImportRule = require("./material-icon-imports"); | ||
|
||
module.exports = { | ||
rules: { | ||
"material-icon-imports": materialIconImportRule, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module.exports = { | ||
meta: { | ||
type: "problem", | ||
docs: { | ||
description: | ||
"Enforce that icons are imported from our own subset of icons instead of the full Material Icons library.", | ||
}, | ||
messages: { | ||
noDirectIconImport: | ||
"Material icons should only be imported from '@icons/material'.", | ||
}, | ||
fixable: "code", | ||
}, | ||
|
||
create(context) { | ||
return { | ||
ImportDeclaration(node) { | ||
const importPath = node.source.value; | ||
|
||
node.specifiers.forEach((specifier) => { | ||
const isMaterialIconImport = | ||
specifier.type === "ImportSpecifier" && | ||
/^mdi[A-Z]/.test(specifier.imported.name); // match 'mdi' followed by a capital letter | ||
|
||
if (isMaterialIconImport && importPath !== "@icons/material") { | ||
context.report({ | ||
node: specifier, | ||
messageId: "noDirectIconImport", | ||
fix: (fixer) => { | ||
return fixer.replaceText(node.source, '"@icons/material"'); | ||
}, | ||
}); | ||
} | ||
}); | ||
}, | ||
}; | ||
}, | ||
}; |
44 changes: 44 additions & 0 deletions
44
lib/eslint-plugin-schulcloud/material-icon-imports.unit.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"use strict"; | ||
|
||
const { RuleTester } = require("eslint"); | ||
const rule = require("./material-icon-imports.js"); | ||
|
||
const ruleTester = new RuleTester({ | ||
parserOptions: { ecmaVersion: 2020, sourceType: "module" }, | ||
}); | ||
|
||
ruleTester.run("material-icon-imports", rule, { | ||
valid: [ | ||
{ | ||
code: `import { mdiCheck } from "@icons/material";`, | ||
}, | ||
{ | ||
code: `import { useI18n } from "vue-i18n";`, | ||
}, | ||
{ | ||
code: `import { mdi } from "vuetify/iconsets/mdi-svg";`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: `import { mdiCheck } from "@mdi/js";`, | ||
errors: [{ messageId: "noDirectIconImport" }], | ||
output: `import { mdiCheck } from "@icons/material";`, | ||
}, | ||
{ | ||
code: `import { mdiAlert } from "@/components/icons/material";`, | ||
errors: [{ messageId: "noDirectIconImport" }], | ||
output: `import { mdiAlert } from "@icons/material";`, | ||
}, | ||
{ | ||
code: `import { mdiCheck } from "some-other-path";`, | ||
errors: [{ messageId: "noDirectIconImport" }], | ||
output: `import { mdiCheck } from "@icons/material";`, | ||
}, | ||
{ | ||
code: `import { mdiCheck } from "../icons/material";`, | ||
errors: [{ messageId: "noDirectIconImport" }], | ||
output: `import { mdiCheck } from "@icons/material";`, | ||
}, | ||
], | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.