Skip to content

Commit

Permalink
chore(lint): fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Tahul committed Jun 28, 2023
1 parent fb92317 commit 1b01f43
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 49 deletions.
2 changes: 1 addition & 1 deletion build/base.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { copyFile, mkdir } from 'fs/promises'
import { copyFile, mkdir } from 'node:fs/promises'
import { createResolver } from '@nuxt/kit'
import { defineBuildConfig } from 'unbuild'

Expand Down
2 changes: 1 addition & 1 deletion build/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'node:path'
import { build } from 'unbuild'
import baseBuildConfig from './base.config'

Expand Down
2 changes: 1 addition & 1 deletion playground/components/ThemeSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const preference = computed(() => {
return 'dark'
})
const toggle = () => {
function toggle() {
toggleCount.value++
const cl = document.querySelector('html')?.classList
if (cl && cl.contains('dark')) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/features/stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function usePinceauRuntimeSheet(
function deleteRule(rule: CSSRule) {
const ruleIndex = Object.values(sheet.value.cssRules).indexOf(rule)

if (typeof ruleIndex === 'undefined' || isNaN(ruleIndex)) { return }
if (typeof ruleIndex === 'undefined' || Number.isNaN(ruleIndex)) { return }

try { sheet.value.deleteRule(ruleIndex) }
catch (e) { /* Continue regardless of errors */ }
Expand Down
6 changes: 2 additions & 4 deletions src/runtime/features/variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import { computed, onScopeDispose, ref, watch } from 'vue'
import type { PinceauRuntimeIds } from '../../types'
import type { PinceauRuntimeSheet } from './stylesheet'

export const usePinceauVariants = (
ids: ComputedRef<PinceauRuntimeIds>,
export function usePinceauVariants(ids: ComputedRef<PinceauRuntimeIds>,
variants: any,
props: any,
sheet: PinceauRuntimeSheet,
classes: Ref<any>,
loc: any,
) => {
loc: any) {
let rule: CSSRule = sheet.hydratableRules?.[ids.value.uid]?.v
const variantsState = computed(() => variants ? resolveVariantsState(ids.value, props, variants) : {})
const variantsClasses = ref<string[]>([])
Expand Down
10 changes: 5 additions & 5 deletions src/theme/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { resolveThemeRule } from '../utils/css'
/**
* Stringify utils from object
*/
const stringifyUtils = (value: Record<string, any>, definitions: any) => {
function stringifyUtils(value: Record<string, any>, definitions: any) {
const entries = Object.entries(value)
return entries.reduce(
(acc, [key, value]) => {
Expand Down Expand Up @@ -40,7 +40,7 @@ const stringifyUtils = (value: Record<string, any>, definitions: any) => {
/**
* Enhance tokens paths list
*/
const enhanceTokenPaths = (value = []) => {
function enhanceTokenPaths(value = []) {
const tokensLiteralNodes = []

value.forEach(([keyPath]) => {
Expand Down Expand Up @@ -88,7 +88,7 @@ export function tsFull(tokensObject: any) {
/**
* import 'pinceau.css'
*/
export const cssFull = (dictionary: Dictionary, options: Options, responsiveTokens: any, colorSchemeMode: ColorSchemeModes) => {
export function cssFull(dictionary: Dictionary, options: Options, responsiveTokens: any, colorSchemeMode: ColorSchemeModes) {
const { formattedVariables } = StyleDictionary.formatHelpers

// Create :root tokens list
Expand Down Expand Up @@ -140,7 +140,7 @@ export const cssFull = (dictionary: Dictionary, options: Options, responsiveToke
/**
* definitions.ts
*/
export const definitionsFull = (definitions: any) => {
export function definitionsFull(definitions: any) {
return `export const definitions = ${JSON.stringify(definitions, null, 2)} as const`
}

Expand All @@ -158,7 +158,7 @@ export function schemaFull(schema: Schema) {
/**
* import utils from '#pinceau/utils'
*/
export const utilsFull = (utils = {}, utilsImports = [], definitions = {}) => {
export function utilsFull(utils = {}, utilsImports = [], definitions = {}) {
let result = 'import { PinceauTheme, PropertyValue } from \'pinceau\'\n'

// Add utilsImports from config
Expand Down
4 changes: 2 additions & 2 deletions src/theme/layers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { existsSync } from 'fs'
import { readFile } from 'fs/promises'
import { existsSync } from 'node:fs'
import { readFile } from 'node:fs/promises'
import createJITI from 'jiti'
import { resolve } from 'pathe'
import type { ConfigFileImport, ConfigLayer, LoadConfigResult, PinceauOptions, PinceauTheme, ResolvedConfigLayer } from '../types'
Expand Down
4 changes: 2 additions & 2 deletions src/theme/output.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { existsSync } from 'fs'
import { mkdir, rm, writeFile } from 'fs/promises'
import { existsSync } from 'node:fs'
import { mkdir, rm, writeFile } from 'node:fs/promises'
import { join } from 'pathe'
import type { PinceauOptions } from '../types'
import { schemaFull, tsFull, utilsFull } from './formats'
Expand Down
6 changes: 2 additions & 4 deletions src/transforms/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ import { resolveRuntimeContents } from './vue/computed'
/**
* Stringify every call of css() into a valid Vue <style> declaration.
*/
export const transformCssFunction = (
id: string,
export function transformCssFunction(id: string,
code = '',
variants: any,
computedStyles: any,
localTokens: any,
ctx: PinceauContext,
loc?: any,
) => {
loc?: any) {
// Enhance error logging for `css()`
try {
parse(code, { ecmaVersion: 'latest' })
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/dt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { dtRegex } from '../utils/regexes'
*
* Supports `wrapper` to be used in both `<style>` and `<script>` or `<template>` tags.
*/
export const transformDtHelper = (code: string, ctx: PinceauContext, wrapper: string | undefined = undefined) => {
export function transformDtHelper(code: string, ctx: PinceauContext, wrapper: string | undefined = undefined) {
const replace = (content: string): string => `${wrapper || ''}${content}${wrapper || ''}`
return code.replace(dtRegex, (_, ...code) => {
const path = code?.[0]
Expand Down
1 change: 1 addition & 0 deletions src/utils/$tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function createTokensHelper(theme: any = {}, options: TokensFunctionOptio
: token
}

// eslint-disable-next-line @typescript-eslint/no-invalid-this
return $tokens.bind(this)
}

Expand Down
8 changes: 4 additions & 4 deletions src/utils/debug.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { performance } from 'perf_hooks'
import { performance } from 'node:perf_hooks'
import type { PinceauOptions } from 'pinceau'
import { debugMarker, getDebugContext } from '../utils/logger'

export const useDebugPerformance = (text: string, debug: PinceauOptions['debug'], logOnStop = true) => {
export function useDebugPerformance(text: string, debug: PinceauOptions['debug'], logOnStop = true) {
const isDebug = debug === 2

const performanceTimerStart = performance.now()
Expand All @@ -16,9 +16,9 @@ export const useDebugPerformance = (text: string, debug: PinceauOptions['debug']
function timing() {
const { error, success, warning } = getDebugContext()

let count = Number(parseFloat(`${performanceTimerStop - performanceTimerStart}`).toFixed(2))
let count = Number(Number.parseFloat(`${performanceTimerStop - performanceTimerStart}`).toFixed(2))

if (isNaN(count)) {
if (Number.isNaN(count)) {
count = 0
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let context: { logger: any; debugLevel: DebugLevel; tag: any; info: any; warning
// chalk.green
success: noopHelper,
}
const updateDebugContext = (newContext: Partial<typeof context>) => {
function updateDebugContext(newContext: Partial<typeof context>) {
context = {
...context,
...newContext,
Expand Down
6 changes: 2 additions & 4 deletions src/utils/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import type { Color } from 'chroma-js'
import chroma from 'chroma-js'
import type { DesignTokens } from '../types'

export const palette = (
color: string,
export function palette(color: string,
suffixes: Array<string | number> = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900],
padding = 0.1,
): DesignTokens => {
padding = 0.1): DesignTokens {
if (!color || typeof color !== 'string') {
throw new Error('Please provide a valid "color" string parameter')
}
Expand Down
18 changes: 6 additions & 12 deletions src/utils/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ import { kebabCase } from 'scule'
const comma = /\s*,\s*(?![^()]*\))/

/** Returns selectors resolved from parent selectors and nested selectors. */
export const getResolvedSelectors = (
/** @type {string[]} Parent selectors (e.g. `["a", "button"]`). */
parentSelectors,
export function getResolvedSelectors(parentSelectors,
/** @type {string[]} Nested selectors (e.g. `["&:hover", "&:focus"]`). */
nestedSelectors,
) => (
parentSelectors.reduce(
nestedSelectors) {
return parentSelectors.reduce(
(resolvedSelectors, parentSelector) => {
resolvedSelectors.push(
...nestedSelectors.map(
Expand All @@ -42,18 +39,15 @@ export const getResolvedSelectors = (
},
[],
)
)
}

/* Grab object prototype to compare in the loop */
const { prototype: { toString } } = Object

/** Returns a string of CSS from an object of CSS. */
export const stringify = (
/** Object representing the current CSS. */
value,
export function stringify(value,
/** Replacer function. */
replacer = undefined,
) => {
replacer = undefined) {
/** Set used to manage the opened and closed state of rules. */
const used = new WeakSet()

Expand Down
4 changes: 2 additions & 2 deletions src/utils/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { walkTokens } from '../utils/data'
/**
* Make a list of `get()` compatible paths for any object.
*/
export const objectPaths = (data: any) => {
export function objectPaths(data: any) {
const output: any = []
function step(obj: any, prev?: string) {
Object.keys(obj).forEach((key) => {
Expand Down Expand Up @@ -33,7 +33,7 @@ export const objectPaths = (data: any) => {
/**
* Flatten tokens object for runtime usage.
*/
export const flattenTokens = (data: any, toValue = false, raw = true) => {
export function flattenTokens(data: any, toValue = false, raw = true) {
return walkTokens(data, (value) => {
// Get slim token value object
const toRet = toValue
Expand Down
4 changes: 2 additions & 2 deletions src/utils/vue.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { readFileSync } from 'fs'
import { readFileSync } from 'node:fs'
import { transformCssFunction, transformStyle } from '../transforms'
import type { PinceauContext, PinceauQuery } from '../types'
import { parseVueComponent } from './ast'

/**
* Will load and transform a Vue <style> query.
*/
export const loadVueStyle = (query: PinceauQuery, ctx: PinceauContext) => {
export function loadVueStyle(query: PinceauQuery, ctx: PinceauContext) {
const { filename } = query

const file = readFileSync(filename, 'utf8')
Expand Down
1 change: 1 addition & 0 deletions src/vite.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import pinceau from './unplugin'

export default pinceau.vite
2 changes: 1 addition & 1 deletion test/fixtures/nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'node:path'
import PinceauModule from '../../../src/nuxt'

export default defineNuxtConfig({
Expand Down
2 changes: 1 addition & 1 deletion test/unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFile } from 'fs/promises'
import { readFile } from 'node:fs/promises'
import type { SFCDescriptor } from 'vue/compiler-sfc'
import { describe, expect, it } from 'vitest'
import { parseVueComponent } from 'pinceau/utils'
Expand Down

0 comments on commit 1b01f43

Please sign in to comment.