From ba9d177891b847af6d234f92cdeb42ef663b45cb Mon Sep 17 00:00:00 2001 From: Brad Cornes Date: Fri, 1 Oct 2021 09:41:27 +0100 Subject: [PATCH] Rename `completions` and remove color information (#5662) --- src/lib/setupContextUtils.js | 20 +++++--------------- tests/completions.test.js | 25 ------------------------- tests/getClassList.test.js | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 40 deletions(-) delete mode 100644 tests/completions.test.js create mode 100644 tests/getClassList.test.js diff --git a/src/lib/setupContextUtils.js b/src/lib/setupContextUtils.js index b3b7c81eb..e3ae20e49 100644 --- a/src/lib/setupContextUtils.js +++ b/src/lib/setupContextUtils.js @@ -631,27 +631,17 @@ function registerPlugins(plugins, context) { return output.map((value) => ({ raw: value, extension: 'html' })) } - // Generate a list of strings for autocompletion purposes. Colors will have a - // tuple with options, e.g.: - // ['uppercase', 'lowercase', ['bg-red', { color: 'rgb(255 0 0)' }]] - context.completions = function () { - // TODO: Try and detect color from components? - // TODO: Should we provide a simple "public api" file with functions? + // Generate a list of strings for autocompletion purposes, e.g. + // ['uppercase', 'lowercase', ...] + context.getClassList = function () { let output = [] for (let util of classList) { if (Array.isArray(util)) { let [utilName, options] = util - let isColor = [].concat(options.type).includes('color') - if (isColor) { - for (let [value, color] of Object.entries(options?.values ?? {})) { - output.push([formatClass(utilName, value), { color }]) - } - } else { - for (let value of Object.keys(options?.values ?? {})) { - output.push(formatClass(utilName, value)) - } + for (let value of Object.keys(options?.values ?? {})) { + output.push(formatClass(utilName, value)) } } else { output.push(util) diff --git a/tests/completions.test.js b/tests/completions.test.js deleted file mode 100644 index 0a259c8ea..000000000 --- a/tests/completions.test.js +++ /dev/null @@ -1,25 +0,0 @@ -import resolveConfig from '../src/public/resolve-config' -import { createContext } from '../src/lib/setupContextUtils' - -it('should generate completions for every possible class, without variants', () => { - let config = {} - - let context = createContext(resolveConfig(config)) - expect(context.completions()).toBeInstanceOf(Array) - - // Verify we have a `container` for the 'components' section. - expect(context.completions()).toContain('container') - - // Verify we handle the DEFAULT case correctly - expect(context.completions()).toContain('border') - - // Verify we handle negative values correctly - expect(context.completions()).toContain('-inset-1/4') - - // Verify we list extra information for colors (!tuples) - let fromBlack = context - .completions() - .find((value) => Array.isArray(value) && value[0] === 'from-black') - - expect(fromBlack).toMatchObject(['from-black', { color: '#000' }]) -}) diff --git a/tests/getClassList.test.js b/tests/getClassList.test.js new file mode 100644 index 000000000..f8f4ab5d2 --- /dev/null +++ b/tests/getClassList.test.js @@ -0,0 +1,18 @@ +import resolveConfig from '../src/public/resolve-config' +import { createContext } from '../src/lib/setupContextUtils' + +it('should generate every possible class, without variants', () => { + let config = {} + + let context = createContext(resolveConfig(config)) + expect(context.getClassList()).toBeInstanceOf(Array) + + // Verify we have a `container` for the 'components' section. + expect(context.getClassList()).toContain('container') + + // Verify we handle the DEFAULT case correctly + expect(context.getClassList()).toContain('border') + + // Verify we handle negative values correctly + expect(context.getClassList()).toContain('-inset-1/4') +})