Skip to content

Commit

Permalink
Merge pull request #913 from 3YOURMIND/use-knip
Browse files Browse the repository at this point in the history
dx(knip): Use knip instead of unimported
  • Loading branch information
Isokaeder authored May 8, 2024
2 parents 9251e37 + af09b3d commit f09156b
Show file tree
Hide file tree
Showing 27 changed files with 481 additions and 212 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const noExtraneousDependenciesOverride = (package) => ({
const noExtraneousDependenciesOverride = (packageName) => ({
'import/no-extraneous-dependencies': [
'error',
{
packageDir: ['.', `./packages/${package}`],
packageDir: ['.', `./packages/${packageName}`],
},
],
})
Expand Down
1 change: 1 addition & 0 deletions .fake-prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
run: yarn install --frozen-lockfile
- name: Run Stylelint
run: yarn run check:stylelint
check-unimported:
check-knip:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -88,8 +88,8 @@ jobs:
key: ${{ hashFiles('**/yarn.lock') }}
- name: Install modules
run: yarn install --frozen-lockfile
- name: Run Unimported
run: yarn run check:unimported
- name: Run Knip
run: yarn run check:knip
check-publint:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.turbo
39 changes: 39 additions & 0 deletions knip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"ignore": ["**/dist/**"],
"ignoreBinaries": [],
"ignoreDependencies": ["lerna", "lint-staged"],
"workspaces": {
"packages/*": {
"entry": ["source/index.ts"],
"project": ["source/**/*.{js,ts,vue}"]
},
"packages/documentation": {
"entry": [
"pages/**/*.vue",
"layouts/**/*.vue",
"plugins/**/*.js",
"nuxt.config.ts"
],
"ignoreDependencies": [
"@nuxt/typescript-build",
"@nuxtjs/markdownit-loader",
"@nuxtjs/markdownit",
"@nuxtjs/style-resources",
"sass-loader",
"ts-loader",
"vue-server-renderer",
"vue-template-compiler"
],
"project": ["**/*.{js,ts,vue}"]
},
"packages/kotti-ui": {
"entry": ["source/index.ts", "tokens/index.js"],
"ignoreDependencies": ["core-js", "normalize.css", "vue-tsc"],
"project": ["source/**/*.{js,ts,vue}"]
},
"packages/yoco": {
"entry": ["source/index.ts", "source/generate.ts"]
}
}
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"eslint-plugin-vitest": "^0.3.22",
"eslint-plugin-vue": "^9.20.1",
"husky": "^7.0.1",
"knip": "^5.13.0",
"lerna": "^7.4.2",
"lint-staged": "^11.0.1",
"nodemon": "^3.0.3",
Expand All @@ -69,12 +70,13 @@
"stylelint": "^15.11.0",
"stylelint-config-recess-order": "^4.3.0",
"stylelint-config-recommended-vue": "^1.5.0",
"stylelint-config-standard": "^33.0.0",
"stylelint-config-standard-scss": "^10.0.0",
"stylelint-csstree-validator": "^3.0.0",
"stylelint-prettier": "^4.0.2",
"turbo": "^1.13.2",
"typescript": "^5.3",
"unimported": "1.31.1"
"vue-eslint-parser": "9"
},
"engines": {
"node": ">=18"
Expand Down Expand Up @@ -111,10 +113,10 @@
"build": "turbo run build",
"check": "turbo run check",
"check:eslint": "turbo run check:eslint",
"check:knip": "turbo run check:knip",
"check:prettier": "turbo run check:prettier",
"check:publint": "turbo run check:publint",
"check:stylelint": "turbo run check:stylelint",
"check:unimported": "turbo run check:unimported",
"fix": "turbo run fix",
"fix:eslint": "turbo run fix:eslint",
"fix:prettier": "turbo run fix:prettier",
Expand Down
2 changes: 1 addition & 1 deletion packages/documentation/data/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export enum Tag {
ZOD = 'zod',
}

export type SubsectionPage = {
type SubsectionPage = {
label: string
tags: Array<Tag>
path: string
Expand Down
2 changes: 0 additions & 2 deletions packages/documentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@types/marked": "^6.0.0",
"@types/natural-sort": "^0.0.24",
"case-sensitive-paths-webpack-plugin": "^2.3.0",
"levenary": "^1.1.1",
"nuxt": "2.x",
"sass-loader": "10.x",
"ts-loader": "8.x",
Expand All @@ -46,7 +45,6 @@
"check:eslint": "yarn --cwd ../.. run eslint --max-warnings=0 --ignore-path=.gitignore ./packages/documentation",
"check:prettier": "yarn --cwd ../.. run prettier --check --ignore-path=.gitignore ./packages/documentation",
"check:stylelint": "stylelint './**/*.{css,scss,vue}'",
"check:unimported": "unimported --no-cache",
"fix:eslint": "yarn run check:eslint --fix",
"fix:prettier": "yarn run check:prettier --write",
"fix:stylelint": "yarn run check:stylelint --fix",
Expand Down
27 changes: 26 additions & 1 deletion packages/documentation/pages/foundations/colors/figma.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,32 @@ import {
tokenColorsFactory,
factoryToFigmaImportable,
} from '@3yourmind/kotti-ui/tokens'
import figmaImportScript from '@3yourmind/kotti-ui/tokens/figma-import-script'
const figmaImportScript = `tokens.forEach(token => {
// edit the style if already existing
const existingStyles = figma.getLocalPaintStyles()
let existing = existingStyles.find(style => style.name === token.name)
let figmaStyle
if (existing) {
figmaStyle = existing
} else {
figmaStyle = figma.createPaintStyle()
}
figmaStyle.name = token.name
figmaStyle.description = token.description
figmaStyle.paints = [
{
type: 'SOLID',
color: {
r: token.color.r / 255,
g: token.color.g / 255,
b: token.color.b / 255,
},
},
]
})`
export default {
name: 'DocumenationPageFoundationsColorsFigma',
Expand Down
12 changes: 12 additions & 0 deletions packages/fake-root/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "fake-root",
"private": true,
"scripts": {
"check:eslint": "yarn --cwd ../.. run eslint --max-warnings=0 --ignore-pattern=packages .",
"check:knip": "yarn --cwd ../.. run knip",
"check:prettier": "yarn --cwd ../.. run prettier --check --ignore-path=.fake-prettierignore --ignore-path=.prettierignore .",
"fix:eslint": "yarn run check:eslint --fix",
"fix:prettier": "yarn run check:prettier --write"
},
"version": "0.0.0"
}
5 changes: 5 additions & 0 deletions packages/fake-root/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Fake Root

This package exists in order to lint the repo root with the same turborepo workflows we can use for ordinary packages.

See https://turbo.build/messages/missing-root-task-in-turbo-json for context as to why this causes an infinite loop without this “root” package.
46 changes: 46 additions & 0 deletions packages/fake-root/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"$schema": "https://turbo.build/schema.json",
"extends": ["//"],
"pipeline": {
"check:eslint": {
"inputs": [
"../../*.{cjs,js,mjs,json,mjs,mts,ts}",
"../../.github/**/*",
"../../.vscode/**/*",
"../../eslint.config.mjs"
]
},
"check:knip": {
"inputs": [
"../../knip.json",
"../../packages/*/scripts/**/*",
"../../packages/*/source/**/*"
]
},
"check:prettier": {
"inputs": [
"../../.fake-prettierignore",
"../../.prettierignore",
"../../*.{cjs,js,mjs,json,mjs,mts,ts}",
"../../.github/**/*",
"../../.vscode/**/*"
]
},
"fix:eslint": {
"inputs": [
"../../*.{cjs,js,mjs,json,mjs,mts,ts}",
"../../.github/**/*",
"../../.vscode/**/*"
]
},
"fix:prettier": {
"inputs": [
"../../.fake-prettierignore",
"../../.prettierignore",
"../../*.{cjs,js,mjs,json,mjs,mts,ts}",
"../../.github/**/*",
"../../.vscode/**/*"
]
}
}
}
1 change: 0 additions & 1 deletion packages/kotti-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
"check:prettier": "yarn --cwd ../.. run prettier --check --ignore-path=.gitignore ./packages/kotti-ui",
"check:publint": "publint",
"check:stylelint": "stylelint 'source/**/*.{css,scss,vue}'",
"check:unimported": "unimported --no-cache",
"fix:eslint": "yarn run check:eslint --fix",
"fix:prettier": "yarn run check:prettier --write",
"fix:stylelint": "yarn run check:stylelint --fix",
Expand Down
1 change: 0 additions & 1 deletion packages/kotti-ui/source/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export const ISO8601 = 'YYYY-MM-DD' as const
export const ISO8601_SECONDS = 'YYYY-MM-DD HH:mm:ss' as const

// eslint-disable-next-line no-magic-numbers
Expand Down
11 changes: 3 additions & 8 deletions packages/kotti-ui/source/kotti-table/logic/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export function getColumnRealIndex(state, column) {
return state._columnsArray.findIndex(({ id }) => id == column.id)
}

export function getColumn(state, column = {}) {
function getColumn(state, column = {}) {
return state._columns[column.prop]
}

export function getColumnIndex(state, column) {
return getColumn(state, column).index
}

export function setColumn(state, { column, index, deleted }) {
function setColumn(state, { column, index, deleted }) {
const { _columns = {} } = state
let newColumn = column
const oldColumn = _columns[newColumn.prop]
Expand Down Expand Up @@ -74,12 +74,7 @@ export function setColumnsArray(
})
}

export function getColumnsArray(state, prop) {
//please be sure to pass state[prop] that has an array type
return [...state[prop]]
}

export function emitColumnsChange(store) {
function emitColumnsChange(store) {
store.table.$ready &&
store.emit(
'columnsChange',
Expand Down
5 changes: 3 additions & 2 deletions packages/kotti-ui/source/kotti-table/logic/disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ export const defaultState = {
enabledRows: [],
isAllRowsDisabled: false,
}
export function getDisabledRows(rows, disableRow) {

function getDisabledRows(rows, disableRow) {
return rows.filter((row, rowIndex) => {
return disableRow ? disableRow({ row, rowIndex }) : false
})
}

export function getEnabledRows(rows, disableRow) {
function getEnabledRows(rows, disableRow) {
return getDisabledRows(rows, negate(disableRow))
}

Expand Down
2 changes: 1 addition & 1 deletion packages/kotti-ui/source/kotti-table/logic/hide.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { setColumnsArray } from './column'

export function getHiddenColumnIndex(state, column) {
function getHiddenColumnIndex(state, column) {
return state.hiddenColumns.findIndex(({ prop }) => prop === column.prop)
}

Expand Down
12 changes: 1 addition & 11 deletions packages/kotti-ui/source/kotti-table/logic/select.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import debounce from 'lodash/debounce'
import isEqual from 'lodash/isEqual'

export function toggleRowSelection(state, row, selected) {
function toggleRowSelection(state, row, selected) {
let changed = false
const selection = state.selection
const index = selection.findIndex((selectedRow) => isEqual(selectedRow, row))
Expand All @@ -24,16 +24,6 @@ export function toggleRowSelection(state, row, selected) {
return changed
}

export function getKeysMap(list, key) {
const map = {}
for (const item of list) map[item[key]] = item
return map
}

export function getRowIdentity(item, key = 'id') {
return item[key]
}

export function updateAllSelected(state) {
const { rows, selection } = state
if (!rows || rows.length === 0 || !selection || selection.length === 0) {
Expand Down
18 changes: 5 additions & 13 deletions packages/kotti-ui/source/kotti-table/logic/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import property from 'lodash/property'
import { IS_ASC, IS_DSC, PUBLIC_SORT_PROPS } from '../constants'
import { KottiTable } from '../types'

import { setColumnsArray, getColumn } from './column'
import { setColumnsArray } from './column'

export function getSortedColumnIndex(state, column) {
function getSortedColumnIndex(state, column) {
return state.sortedColumns.findIndex(({ prop }) => prop === column.prop)
}

Expand All @@ -25,19 +25,11 @@ export function setSortedColumn(state, column) {
}
}

export function setSortedColumns(state, columns) {
state.sortedColumns = columns.map((column) => {
column = pick(column, ['prop', 'sortOrder'])
const oldColumn = getColumn(state, column) || {}
return Object.assign(oldColumn, column)
})
}

export function getSortedColumn(state, column) {
function getSortedColumn(state, column) {
return state.sortedColumns[getSortedColumnIndex(state, column)]
}

export function getNextSortOrder(column) {
function getNextSortOrder(column) {
const length = column.sortOrders.length
const index = (column.sortOrders.indexOf(column.sortOrder) + 1) % length
return column.sortOrders[Math.max(index, 0)]
Expand Down Expand Up @@ -78,7 +70,7 @@ function compare(order, a, b, { sortMethod, sortBy, sortOrder }) {
return order * sortOrder
}

export function orderBy(array, sortedColumns) {
function orderBy(array, sortedColumns) {
const columns = sortedColumns.map((column) => {
const { prop, sortMethod } = column

Expand Down
3 changes: 1 addition & 2 deletions packages/kotti-ui/source/kotti-table/mixins.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
declare const TableColumnsStateMixin: any
declare const tableInjectedMixin: any
export { TableColumnsStateMixin, tableInjectedMixin }
export { TableColumnsStateMixin }
11 changes: 1 addition & 10 deletions packages/kotti-ui/source/kotti-table/mixins.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import {
KT_LAYOUT,
KT_STORE,
KT_TABLE_STATE_PROVIDER,
KT_TABLE,
} from './constants'

export const tableInjectedMixin = {
inject: { KT_TABLE, KT_STORE, KT_LAYOUT },
}
import { KT_STORE, KT_TABLE_STATE_PROVIDER, KT_TABLE } from './constants'

export const TableColumnsStateMixin = {
inject: {
Expand Down
Loading

0 comments on commit f09156b

Please sign in to comment.