Skip to content

Commit

Permalink
migrate to ES Mmodules syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Ezequiel Fabbroni Assum committed Oct 4, 2024
1 parent cff76a0 commit 1a63c33
Show file tree
Hide file tree
Showing 23 changed files with 335 additions and 922 deletions.
47 changes: 23 additions & 24 deletions configs/base.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
const globals = require('globals');
/* eslint-disable import/extensions */
import globals from 'globals';

const { isPackageAvailable } = require('../utils');
import { isPackageAvailable } from '../utils.js';
import bestPractices from './best-practices.js';
import errors from './errors.js';
import es6 from './es6.js';
import formats from './formats.js';
import imports from './imports.js';
import jest from './jest.js';
import lodash from './lodash.js';
import node from './node.js';
import postcss from './postcss.js';
import promises from './promises.js';
import react from './react.js';
import reactA11y from './react-a11y.js';
import storybook from './storybook.js';
import strict from './strict.js';
import style from './style.js';
import ts from './ts.js';
import variables from './variables.js';

const isTSAvailable = isPackageAvailable('typescript');
const isJestAvailable = isPackageAvailable('jest');

const storybook = require('./storybook');
const ts = require('./ts');
const postcss = require('./postcss');

const bestPractices = require('./best-practices');
const errors = require('./errors');
const es6 = require('./es6');
const imports = require('./imports');
const node = require('./node');
const promises = require('./promises');
const strict = require('./strict');
const style = require('./style');
const variables = require('./variables');
const react = require('./react');
const lodash = require('./lodash');
const reactA11y = require('./react-a11y');
const jest = require('./jest');
const formats = require('./formats');
const isTSAvailable = await isPackageAvailable('typescript');
const isJestAvailable = await isPackageAvailable('jest');

const configs = [
bestPractices,
Expand Down Expand Up @@ -56,7 +55,7 @@ const overrides = [
},
].filter(Boolean);

module.exports = [
export default [
...configs,
{
name: 'base-cabify-eslint-config',
Expand Down
2 changes: 1 addition & 1 deletion configs/best-practices.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'best-practices-cabify-eslint-config',
rules: {
// enforces getter/setter pairs in objects
Expand Down
2 changes: 1 addition & 1 deletion configs/errors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'errors-cabify-eslint-config',
rules: {
// Enforce “for” loop update clause moving the counter in the right direction
Expand Down
2 changes: 1 addition & 1 deletion configs/es6.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'ES6-cabify-eslint-config',
// languageOptions: {
// globals: {
Expand Down
4 changes: 2 additions & 2 deletions configs/formats.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';

module.exports = {
export default {
name: 'formats-cabify-eslint-config',
...eslintPluginPrettierRecommended,
};
6 changes: 3 additions & 3 deletions configs/imports.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const importPlugin = require('eslint-plugin-import');
const simpleImportSort = require('eslint-plugin-simple-import-sort');
import importPlugin from 'eslint-plugin-import';
import simpleImportSort from 'eslint-plugin-simple-import-sort';

module.exports = {
export default {
name: 'imports-cabify-eslint-config',
// languageOptions: {
// globals: {
Expand Down
4 changes: 2 additions & 2 deletions configs/jest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const jest = require('eslint-plugin-jest');
import jest from 'eslint-plugin-jest';

module.exports = {
export default {
name: 'jest-cabify-eslint-config',
...jest.configs['flat/recommended'],
rules: {
Expand Down
4 changes: 2 additions & 2 deletions configs/lodash.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const lodashPlugin = require('eslint-plugin-lodash');
import lodashPlugin from 'eslint-plugin-lodash';

module.exports = {
export default {
name: 'lodash-cabify-eslint-config',
plugins: { lodash: lodashPlugin },
rules: {
Expand Down
2 changes: 1 addition & 1 deletion configs/node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'node-cabify-eslint-config',
rules: {
// enforce return after a callback
Expand Down
2 changes: 1 addition & 1 deletion configs/postcss.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'post-css-cabify-eslint-config',
rules: {
'global-require': 'off',
Expand Down
2 changes: 1 addition & 1 deletion configs/promises.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'promises-cabify-eslint-config',
rules: {
'no-floating-promises': 'off',
Expand Down
4 changes: 2 additions & 2 deletions configs/react-a11y.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const jsxAllyPlugin = require('eslint-plugin-jsx-a11y');
import jsxAllyPlugin from 'eslint-plugin-jsx-a11y';

module.exports = {
export default {
name: 'react-a11y-cabify-eslint-config',
plugins: { 'jsx-a11y': jsxAllyPlugin },

Expand Down
6 changes: 3 additions & 3 deletions configs/react.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const react = require('eslint-plugin-react');
const reactHooks = require('eslint-plugin-react-hooks');
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';

module.exports = {
export default {
name: 'react-cabify-eslint-config',
plugins: {
react,
Expand Down
2 changes: 1 addition & 1 deletion configs/storybook.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'storybook-cabify-eslint-config',
rules: {
'import/no-default-export': 'off',
Expand Down
2 changes: 1 addition & 1 deletion configs/strict.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'strict-cabify-eslint-config',
rules: {
// babel inserts `'use strict';` for us
Expand Down
2 changes: 1 addition & 1 deletion configs/style.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'style-cabify-eslint-config',
rules: {
// require camel case names
Expand Down
11 changes: 5 additions & 6 deletions configs/ts.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module.exports = {
// eslint-disable-next-line import/no-unresolved
import tseslint from 'typescript-eslint';

export default {
name: 'ts-cabify-eslint-config',
plugins: ['@typescript-eslint'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
...tseslint.configs.recommended,
rules: {
'@typescript-eslint/restrict-template-expressions': [
'error',
Expand Down
4 changes: 2 additions & 2 deletions configs/variables.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const confusingBrowserGlobals = require('confusing-browser-globals');
import confusingBrowserGlobals from 'confusing-browser-globals';

module.exports = {
export default {
name: 'variables-cabify-eslint-config',
rules: {
// enforce or disallow variable initializations at definition
Expand Down
5 changes: 3 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const recommended = require('./recommended');
// eslint-disable-next-line import/extensions
import recommended from './recommended.js';

module.exports = [...recommended];
export default [...recommended];
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@cabify/eslint-config",
"version": "3.0.1-beta-6",
"description": "ESLint config for Cabify Javascript projects",
"type": "module",
"scripts": {
"build": "echo 'No build to perform'",
"test": "npm run lint:check && npm run format:check",
Expand Down Expand Up @@ -38,6 +39,7 @@
".": "./recommended.js"
},
"dependencies": {
"typescript-eslint": "^8.8.0",
"@typescript-eslint/eslint-plugin": "^8.4.0",
"@typescript-eslint/parser": "^8.4.0",
"confusing-browser-globals": "^1.0.10",
Expand All @@ -57,8 +59,11 @@
"prettier": ">= 2.2.1"
},
"devDependencies": {
"eslint": "9.11.0",
"prettier": "3.3.3"
"@eslint/js": "^9.11.1",
"@types/eslint__js": "^8.42.3",
"eslint": "^9.11.1",
"prettier": "3.3.3",
"typescript": "^5.6.2"
},
"publishConfig": {
"access": "public"
Expand Down
8 changes: 5 additions & 3 deletions recommended.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const base = require('./configs/base');
const eslintConfigPrettier = require('eslint-config-prettier');
import eslintConfigPrettier from 'eslint-config-prettier';

module.exports = [...base, eslintConfigPrettier];
// eslint-disable-next-line import/extensions
import base from './configs/base.js';

export default [...base, eslintConfigPrettier];
22 changes: 11 additions & 11 deletions utils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module.exports = {
isPackageAvailable(packageName) {
try {
// eslint-disable-next-line global-require, import/no-dynamic-require
return !!require(packageName);
// eslint-disable-next-line no-unused-vars
} catch (e) {
return false;
}
},
};
/* eslint-disable no-unused-vars */
// eslint-disable-next-line import/prefer-default-export
export async function isPackageAvailable(packageName) {
try {
// Dynamically import the package
await import(packageName);
return true;
} catch (_) {
return false;
}
}
Loading

0 comments on commit 1a63c33

Please sign in to comment.