Skip to content

Commit b1a6203

Browse files
committed
Enforce use of type-only imports.
1 parent 2343746 commit b1a6203

40 files changed

+90
-62
lines changed

config/modules/postcss-easy-import.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
declare module 'postcss-easy-import' {
2-
import { Plugin } from 'postcss'
2+
import type { Plugin } from 'postcss'
33

44
export default function (opts: {
55
prefix: string | boolean

config/modules/postcss-hexrgba.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
declare module 'postcss-hexrgba' {
2-
import { Plugin } from 'postcss'
2+
import type { Plugin } from 'postcss'
33
export default function (): Plugin
44
}

config/modules/webpack-rtl-plugin.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
declare module 'webpack-rtl-plugin' {
2-
import { ConfigOptions, Plugin } from 'rtlcss'
3-
import cssnano from 'cssnano'
4-
import webpack, { WebpackPluginInstance } from 'webpack'
2+
import type { ConfigOptions, Plugin } from 'rtlcss'
3+
import type cssnano from 'cssnano'
4+
import type { WebpackPluginInstance } from 'webpack'
5+
import type webpack from 'webpack'
56

67
class WebpackRtlPlugin implements WebpackPluginInstance {
78
constructor(options?: {

config/webpack-css.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path'
2-
import { Configuration, EntryObject } from 'webpack'
3-
import { Config as PostCssConfig } from 'postcss-load-config'
2+
import type { Configuration, EntryObject } from 'webpack'
3+
import type { Config as PostCssConfig } from 'postcss-load-config'
44
import libsass from 'sass'
55
import cssnano from 'cssnano'
66
import autoprefixer from 'autoprefixer'
@@ -30,7 +30,7 @@ export const cssWebpackConfig: Configuration = {
3030
entry: {
3131
...entriesFromFiles(
3232
['src/css/*.scss', '!src/css/**/_*.scss'],
33-
filename => `${path.parse(filename).name}-style`
33+
filename => `${path.parse(filename).name}-css`
3434
),
3535
...entriesFromFiles(
3636
'node_modules/codemirror/theme/*.css',
@@ -96,7 +96,7 @@ export const cssWebpackConfig: Configuration = {
9696
chunk?.name ?
9797
`${chunk.name}.css`
9898
.replace(/^codemirror-theme-/, 'editor-themes/')
99-
.replace(/-style\.css$/, '.css') :
99+
.replace(/-css\.css$/, '.css') :
100100
'[name].css'
101101
}),
102102
new WebpackRTLPlugin({

config/webpack-js.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { DefinePlugin, Configuration } from 'webpack'
1+
import type { Configuration } from 'webpack'
2+
import { DefinePlugin } from 'webpack'
23
import { join, resolve } from 'path'
34
import ESLintPlugin from 'eslint-webpack-plugin'
45
import RemoveEmptyScriptsPlugin from 'webpack-remove-empty-scripts'

eslint.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ export default typescript.config(
5858
assertionStyle: 'angle-bracket',
5959
objectLiteralTypeAssertions: 'never'
6060
}],
61+
'@typescript-eslint/consistent-type-imports': 'error',
62+
'@typescript-eslint/consistent-type-exports': 'error',
6163
'@typescript-eslint/no-confusing-void-expression': ['error', { ignoreArrowShorthand: true }],
6264
'@typescript-eslint/no-for-in-array': 'error',
65+
'@typescript-eslint/no-import-type-side-effects': 'error',
6366
'@typescript-eslint/no-inferrable-types': ['error', { ignoreProperties: true, ignoreParameters: false }],
6467
'@typescript-eslint/no-unused-vars': ['error', {
6568
argsIgnorePattern: '^_',

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
"description": "Manage code snippets running on a WordPress-powered site through a graphical interface.",
44
"homepage": "https://wordpress.org/plugins/code-snippets",
55
"version": "3.6.5.1",
6-
"main": "dist/edit.js",
6+
"main": "src/dist/edit.js",
77
"directories": {
88
"test": "tests"
99
},
1010
"scripts": {
1111
"test": "eslint && npm run phpcs",
12-
"build": "webpack --mode development",
13-
"watch": "webpack --mode development --watch",
12+
"build": "webpack",
13+
"watch": "webpack --watch",
1414
"bundle": "ts-node scripts/bundle.ts",
1515
"phpcs": "src/vendor/bin/phpcs -s --colors ./phpcs.xml",
1616
"phpcbf": "src/vendor/bin/phpcbf ./phpcs.xml",

scripts/bundle.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { spawn } from 'child_process'
22
import { createWriteStream } from 'fs'
33
import * as process from 'node:process'
4-
import { webpack as webpackAsync, Configuration } from 'webpack'
4+
import type { Configuration } from 'webpack'
5+
import { webpack as webpackAsync } from 'webpack'
56
import plugin from '../package.json'
67
import webpackConfig from '../webpack.config'
78
import { cleanup, copy, resolve } from './utils/files'

src/js/components/SnippetForm/SnippetEditor/CodeEditorShortcuts.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { __, _x } from '@wordpress/i18n'
22
import classnames from 'classnames'
33
import React from 'react'
4-
import { KEYBOARD_KEYS, KeyboardShortcut } from '../../../types/KeyboardShortcut'
4+
import type { KeyboardShortcut } from '../../../types/KeyboardShortcut'
5+
import { KEYBOARD_KEYS } from '../../../types/KeyboardShortcut'
56
import { isMacOS } from '../../../utils/general'
67

78
const shortcuts: KeyboardShortcut[] = [

src/js/components/SnippetForm/SnippetEditor/SnippetEditor.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React, { useEffect } from 'react'
22
import { __, _x } from '@wordpress/i18n'
33
import { addQueryArgs } from '@wordpress/url'
4-
import { Editor, EditorConfiguration } from 'codemirror'
5-
import { SNIPPET_TYPE_SCOPES, SNIPPET_TYPES, SnippetScope, SnippetType } from '../../../types/Snippet'
4+
import type { Editor, EditorConfiguration } from 'codemirror'
5+
import type { SnippetScope, SnippetType } from '../../../types/Snippet'
6+
import { SNIPPET_TYPE_SCOPES, SNIPPET_TYPES } from '../../../types/Snippet'
67
import '../../../editor'
78
import { isLicensed } from '../../../utils/general'
89
import { getSnippetType, isProType } from '../../../utils/snippets'

src/js/components/SnippetForm/buttons/ExportButtons.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react'
2-
import { AxiosResponse } from 'axios'
2+
import type { AxiosResponse } from 'axios'
33
import { __ } from '@wordpress/i18n'
44
import { Button } from '../../common/Button'
5-
import { SnippetsExport } from '../../../types/SnippetsExport'
5+
import type { SnippetsExport } from '../../../types/SnippetsExport'
66
import { useSnippetsAPI } from '../../../hooks/useSnippets'
77
import { downloadSnippetExportFile } from '../../../utils/files'
88
import { useSnippetForm } from '../../../hooks/useSnippetForm'

src/js/components/SnippetForm/buttons/SubmitButtons.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React, { useState } from 'react'
22
import { __ } from '@wordpress/i18n'
33
import { handleUnknownError } from '../../../utils/errors'
4-
import { Button, ButtonProps } from '../../common/Button'
4+
import type { ButtonProps } from '../../common/Button'
5+
import { Button } from '../../common/Button'
56
import { ConfirmDialog } from '../../common/ConfirmDialog'
6-
import { Snippet } from '../../../types/Snippet'
7+
import type { Snippet } from '../../../types/Snippet'
78
import { isNetworkAdmin } from '../../../utils/general'
89
import { useSnippetForm } from '../../../hooks/useSnippetForm'
910

src/js/components/SnippetForm/fields/ScopeInput.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { ExternalLink } from '@wordpress/components'
22
import { __ } from '@wordpress/i18n'
3-
import React, { Dispatch, SetStateAction, useState } from 'react'
4-
import { SNIPPET_TYPE_SCOPES, SNIPPET_TYPES, SnippetScope } from '../../../types/Snippet'
3+
import type { Dispatch, SetStateAction} from 'react'
4+
import React, { useState } from 'react'
5+
import type { SnippetScope } from '../../../types/Snippet'
6+
import { SNIPPET_TYPE_SCOPES, SNIPPET_TYPES } from '../../../types/Snippet'
57
import { isNetworkAdmin } from '../../../utils/general'
6-
import { buildShortcodeTag, ShortcodeAtts } from '../../../utils/shortcodes'
8+
import type { ShortcodeAtts } from '../../../utils/shortcodes'
9+
import { buildShortcodeTag } from '../../../utils/shortcodes'
710
import { getSnippetType } from '../../../utils/snippets'
811
import { CopyToClipboardButton } from '../../common/CopyToClipboardButton'
912
import { useSnippetForm } from '../../../hooks/useSnippetForm'

src/js/components/SnippetForm/page/Notices.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import classnames from 'classnames'
2-
import React, { MouseEventHandler, ReactNode, useEffect } from 'react'
2+
import type { MouseEventHandler, ReactNode} from 'react'
3+
import React, { useEffect } from 'react'
34
import { __, sprintf } from '@wordpress/i18n'
45
import { useSnippetForm } from '../../../hooks/useSnippetForm'
56

src/js/components/SnippetForm/page/UpgradeDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { Dispatch, SetStateAction, useState } from 'react'
1+
import type { Dispatch, SetStateAction} from 'react'
2+
import React, { useState } from 'react'
23
import { ExternalLink, Modal } from '@wordpress/components'
34
import { __, _n, sprintf } from '@wordpress/i18n'
45

src/js/components/TagEditor/TagEditor.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* Code based on Tagger, copyright (c) 2018-2022 Jakub T. Jankiewicz <https://jcubic.pl/me>
33
* Released under the MIT license.
44
*/
5-
import React, { InputHTMLAttributes, KeyboardEventHandler, useRef, useState } from 'react'
5+
import type { InputHTMLAttributes, KeyboardEventHandler} from 'react'
6+
import React, { useRef, useState } from 'react'
67
import { handleUnknownError } from '../../utils/errors'
78
import { SuggestionList } from './SuggestionList'
89
import { TagList } from './TagList'

src/js/components/common/Button.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { ButtonHTMLAttributes } from 'react'
1+
import type { ButtonHTMLAttributes } from 'react'
2+
import React from 'react'
23
import classnames from 'classnames'
34

45
export interface ButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'id' | 'name'> {

src/js/components/common/ConfirmDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { ReactNode } from 'react'
1+
import type { ReactNode } from 'react'
2+
import React from 'react'
23
import { __ } from '@wordpress/i18n'
34
import { Modal, Flex, Button } from '@wordpress/components'
45

src/js/components/common/CopyToClipboardButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { HTMLAttributes, MouseEventHandler, useState } from 'react'
1+
import type { HTMLAttributes, MouseEventHandler} from 'react'
2+
import React, { useState } from 'react'
23
import { handleUnknownError } from '../../utils/errors'
34

45
const TIMEOUT = 3000

src/js/editor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { registerHelper, defineMode, getMode, EditorConfiguration, ModeSpec } from 'codemirror'
1+
import type { EditorConfiguration, ModeSpec } from 'codemirror'
2+
import { registerHelper, defineMode, getMode } from 'codemirror'
23
import { Linter } from './utils/Linter'
34

45
interface ModeSpecOptions {

src/js/hooks/useAxios.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useMemo } from 'react'
2-
import axios, { AxiosInstance, AxiosResponse, CreateAxiosDefaults } from 'axios'
2+
import type { AxiosInstance, AxiosResponse, CreateAxiosDefaults } from 'axios'
3+
import axios from 'axios'
34

45
export interface AxiosAPI {
56
get: <T>(url: string) => Promise<AxiosResponse<T, never>>

src/js/hooks/useSnippetForm.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { isAxiosError } from 'axios'
2-
import React, { createContext, Dispatch, PropsWithChildren, SetStateAction, useCallback, useContext, useMemo, useState } from 'react'
3-
import { ScreenNotice } from '../types/ScreenNotice'
4-
import { Snippet } from '../types/Snippet'
5-
import { CodeEditorInstance } from '../types/WordPressCodeEditor'
2+
import type { Dispatch, PropsWithChildren, SetStateAction} from 'react'
3+
import React, { createContext, useCallback, useContext, useMemo, useState } from 'react'
4+
import type { ScreenNotice } from '../types/ScreenNotice'
5+
import type { Snippet } from '../types/Snippet'
6+
import type { CodeEditorInstance } from '../types/WordPressCodeEditor'
67
import { isLicensed } from '../utils/general'
78
import { isProSnippet } from '../utils/snippets'
89
import { useSnippetSubmit } from './useSnippetSubmit'

src/js/hooks/useSnippetSubmit.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { __ } from '@wordpress/i18n'
22
import { addQueryArgs } from '@wordpress/url'
33
import { isAxiosError } from 'axios'
4-
import { Dispatch, SetStateAction, useCallback } from 'react'
5-
import { ScreenNotice } from '../types/ScreenNotice'
6-
import { Snippet } from '../types/Snippet'
4+
import type { Dispatch, SetStateAction} from 'react'
5+
import { useCallback } from 'react'
6+
import type { ScreenNotice } from '../types/ScreenNotice'
7+
import type { Snippet } from '../types/Snippet'
78
import { useSnippetsAPI } from './useSnippets'
89

910
const getSuccessNotice = (request: Snippet, response: Snippet, active: boolean | undefined) => {

src/js/hooks/useSnippets.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { useEffect, useMemo, useState } from 'react'
2-
import { AxiosResponse, CreateAxiosDefaults } from 'axios'
2+
import type { AxiosResponse, CreateAxiosDefaults } from 'axios'
33
import { addQueryArgs } from '@wordpress/url'
4-
import { SnippetsExport } from '../types/SnippetsExport'
5-
import { Snippet } from '../types/Snippet'
4+
import type { SnippetsExport } from '../types/SnippetsExport'
5+
import type { Snippet } from '../types/Snippet'
66
import { handleUnknownError } from '../utils/errors'
77
import { isNetworkAdmin } from '../utils/general'
88
import { useAxios } from './useAxios'

src/js/mce.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as tinymce from 'tinymce'
2-
import { Editor } from 'tinymce'
3-
import { ContentShortcodeAtts, SourceShortcodeAtts } from './types/Shortcodes'
4-
import { LocalisedEditor } from './types/WordPressEditor'
2+
import type { Editor } from 'tinymce'
3+
import type { ContentShortcodeAtts, SourceShortcodeAtts } from './types/Shortcodes'
4+
import type { LocalisedEditor } from './types/WordPressEditor'
55

66
const convertToValues = (array: Record<string, string>) =>
77
Object.keys(array).map(key => ({

src/js/services/manage/activation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { __ } from '@wordpress/i18n'
2-
import { Snippet } from '../../types/Snippet'
2+
import type { Snippet } from '../../types/Snippet'
33
import { updateSnippet } from './requests'
44

55
/**

src/js/services/manage/priority.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Snippet } from '../../types/Snippet'
1+
import type { Snippet } from '../../types/Snippet'
22
import { updateSnippet } from './requests'
33

44
/**

src/js/services/manage/requests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Snippet, SnippetScope } from '../../types/Snippet'
1+
import type { Snippet, SnippetScope } from '../../types/Snippet'
22
import { isNetworkAdmin } from '../../utils/general'
33

44
export interface ResponseData<T = unknown> {

src/js/types/SelectOption.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GroupBase } from 'react-select'
1+
import type { GroupBase } from 'react-select'
22

33
export interface SelectOption<T> {
44
readonly value: T

src/js/types/SnippetsExport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Snippet } from './Snippet'
1+
import type { Snippet } from './Snippet'
22

33
export interface SnippetsExport {
44
generator: string

src/js/types/Window.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import tinymce from 'tinymce'
2-
import { Snippet } from './Snippet'
3-
import { CodeEditorInstance, EditorOption, WordPressCodeEditor } from './WordPressCodeEditor'
4-
import { WordPressEditor } from './WordPressEditor'
1+
import type tinymce from 'tinymce'
2+
import type { Snippet } from './Snippet'
3+
import type { CodeEditorInstance, EditorOption, WordPressCodeEditor } from './WordPressCodeEditor'
4+
import type { WordPressEditor } from './WordPressEditor'
55

66
declare global {
77
interface Window {

src/js/types/WordPressCodeEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Editor, EditorConfiguration } from 'codemirror'
1+
import type { Editor, EditorConfiguration } from 'codemirror'
22

33
export interface EditorOption {
44
name: string

src/js/types/WordPressEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import tinymce from 'tinymce'
1+
import type tinymce from 'tinymce'
22

33
export interface VisualEditorSettings {
44
tinymce: boolean | tinymce.Settings & {

src/js/types/wp/Page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Post } from './Post'
1+
import type { Post } from './Post'
22

33
export const PAGES_ENDPOINT = '/wp/v2/pages'
44

src/js/utils/Linter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131
*/
3232

33-
import { Block, Location, Node, Engine } from 'php-parser'
33+
import type { Block, Location, Node} from 'php-parser'
34+
import { Engine } from 'php-parser'
3435
import CodeMirror from 'codemirror'
3536

3637
export interface Annotation {

src/js/utils/files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Snippet } from '../types/Snippet'
1+
import type { Snippet } from '../types/Snippet'
22
import { getSnippetType } from './snippets'
33

44
const SECOND_IN_MS = 1000

src/js/utils/restAPI.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'
1+
import type { AxiosRequestConfig, AxiosResponse } from 'axios'
2+
import axios from 'axios'
23
import { trimLeadingChar, trimTrailingChar } from './text'
34

45
const REST_BASE = window.CODE_SNIPPETS?.restAPI.base ?? ''

src/js/utils/snippets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Snippet, SnippetScope, SnippetType } from '../types/Snippet'
1+
import type { Snippet, SnippetScope, SnippetType } from '../types/Snippet'
22
import { isNetworkAdmin } from './general'
33

44
const PRO_TYPES: SnippetType[] = ['css', 'js']

tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
"compilerOptions": {
44
"allowSyntheticDefaultImports": true,
55
"downlevelIteration": true,
6+
"forceConsistentCasingInFileNames": true,
67
"noImplicitAny": true,
8+
"noImplicitReturns": true,
9+
"noUnusedLocals": true,
10+
"noUnusedParameters": true,
711
"resolveJsonModule": true,
812
"skipLibCheck": false,
913
"jsx": "react"

webpack.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Configuration } from 'webpack'
1+
import type { Configuration } from 'webpack'
22
import { merge } from 'webpack-merge'
33
import { cssWebpackConfig } from './config/webpack-css'
44
import { jsWebpackConfig } from './config/webpack-js'

0 commit comments

Comments
 (0)