Skip to content

Commit

Permalink
Fix linting errors, including pre-commit lint hook (#1659)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicegamer7 authored Aug 4, 2023
1 parent d0aa579 commit f8ea7d8
Show file tree
Hide file tree
Showing 74 changed files with 710 additions and 941 deletions.
1 change: 1 addition & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ engines:
- php
eslint:
enabled: true
channel: "eslint-8"
fixme:
enabled: true
ratings:
Expand Down
17 changes: 10 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"extends": [
"airbnb",
"prettier",
"prettier/react",
"plugin:testing-library/recommended",
"plugin:jest-dom/recommended"
"prettier"
],
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 8,
"ecmaFeatures": {
Expand All @@ -18,8 +15,7 @@
"env": {
"browser": true,
"node": true,
"jquery": true,
"jest": true
"jquery": true
},
"rules": {
"no-debugger": 0,
Expand All @@ -30,6 +26,10 @@
"argsIgnorePattern": "res|next|^err"
}
],
"prefer-arrow-callback": [
"error", {
"allowNamedFunctions": true
}],
"prefer-const": [
"error",
{
Expand Down Expand Up @@ -77,6 +77,9 @@
"extensions": [".js", ".jsx"]
}
],
"react/no-unknown-property": ["error", {
"ignore": ["i18nIsDynamicList"]
}],
"radix": 0,
"no-shadow": [
2,
Expand Down
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/dist/**/*.js
**/react-i18next.js
**/react-i18next.min.js
2 changes: 1 addition & 1 deletion example/locize/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function MyComponent() {
function Page() {
const { t, i18n } = useTranslation();

const changeLanguage = lng => {
const changeLanguage = (lng) => {
i18n.changeLanguage(lng);
};

Expand Down
2 changes: 1 addition & 1 deletion example/razzle-ssr/src/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import logo from './react.svg';
import './Home.css';

function Home() {
const [ t ] = useTranslation('translations');
const [t] = useTranslation('translations');

return (
<div className="Home">
Expand Down
4 changes: 2 additions & 2 deletions example/razzle-ssr/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import express from 'express';
import app from './server';

if (module.hot) {
module.hot.accept('./server', function() {
module.hot.accept('./server', function () {
console.log('🔁 HMR Reloading `./server`...');
});
console.info('✅ Server-side HMR Enabled!');
Expand All @@ -12,7 +12,7 @@ const port = process.env.PORT || 3000;

export default express()
.use((req, res) => app.handle(req, res))
.listen(port, function(err) {
.listen(port, function (err) {
if (err) {
console.error(err);
return;
Expand Down
2 changes: 1 addition & 1 deletion example/react-icu/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
document.getElementById('root'),
);

// If you want your app to work offline and load faster, you can change
Expand Down
24 changes: 10 additions & 14 deletions example/react-icu/src/serviceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ const isLocalhost = Boolean(
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/),
);

export function register(config) {
Expand All @@ -43,7 +41,7 @@ export function register(config) {
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA'
'worker. To learn more, visit https://bit.ly/CRA-PWA',
);
});
} else {
Expand All @@ -57,7 +55,7 @@ export function register(config) {
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
.then((registration) => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
Expand All @@ -71,7 +69,7 @@ function registerValidSW(swUrl, config) {
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
'tabs for this page are closed. See https://bit.ly/CRA-PWA.',
);

// Execute callback
Expand All @@ -93,7 +91,7 @@ function registerValidSW(swUrl, config) {
};
};
})
.catch(error => {
.catch((error) => {
console.error('Error during service worker registration:', error);
});
}
Expand All @@ -103,15 +101,15 @@ function checkValidServiceWorker(swUrl, config) {
fetch(swUrl, {
headers: { 'Service-Worker': 'script' },
})
.then(response => {
.then((response) => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
navigator.serviceWorker.ready.then((registration) => {
registration.unregister().then(() => {
window.location.reload();
});
Expand All @@ -122,19 +120,17 @@ function checkValidServiceWorker(swUrl, config) {
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
console.log('No internet connection found. App is running in offline mode.');
});
}

export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready
.then(registration => {
.then((registration) => {
registration.unregister();
})
.catch(error => {
.catch((error) => {
console.error(error.message);
});
}
Expand Down
2 changes: 1 addition & 1 deletion example/react-native/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { initReactI18next, useTranslation } from 'react-i18next';
const languageDetector = {
type: 'languageDetector',
async: true,
detect: cb => cb('en'),
detect: (cb) => cb('en'),
init: () => {},
cacheUserLanguage: () => {},
};
Expand Down
2 changes: 1 addition & 1 deletion example/react-native/app.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "Example",
"displayName": "Example"
}
}
4 changes: 2 additions & 2 deletions example/react-native/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @format
*/

import {AppRegistry} from 'react-native';
import { AppRegistry } from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import { name as appName } from './app.json';

AppRegistry.registerComponent(appName, () => App);
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
{
"images" : [
"images": [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
"idiom": "iphone",
"size": "29x29",
"scale": "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
"idiom": "iphone",
"size": "29x29",
"scale": "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
"idiom": "iphone",
"size": "40x40",
"scale": "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
"idiom": "iphone",
"size": "40x40",
"scale": "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
"idiom": "iphone",
"size": "60x60",
"scale": "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
"idiom": "iphone",
"size": "60x60",
"scale": "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"info": {
"version": 1,
"author": "xcode"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"info": {
"version": 1,
"author": "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useTranslation } from "react-i18next";
import { useTranslation } from 'react-i18next';

function Comp1() {
const {t} = useTranslation();
const { t } = useTranslation();

return (
<div className="App">
Expand All @@ -12,4 +12,4 @@ function Comp1() {
);
}

export default Comp1;
export default Comp1;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useTranslation } from "react-i18next";
import { useTranslation } from 'react-i18next';

function Comp2() {
const {t} = useTranslation('ns2');
const { t } = useTranslation('ns2');

return (
<div className="App">
Expand All @@ -11,4 +11,4 @@ function Comp2() {
);
}

export default Comp2;
export default Comp2;
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"part1": "This is a simple example.",
"part2": "😉"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"part1": "In order to infer the appropriate type for t function, you should use type augmentation to override the Resources type.",
"part2": "Check out the @types/i18next to see an example."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';

const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
</React.StrictMode>,
);
10 changes: 2 additions & 8 deletions example/react-typescript/simple-multi-namespaces/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
Expand All @@ -20,7 +16,5 @@
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
"include": ["src"]
}
8 changes: 3 additions & 5 deletions example/react-typescript/simple/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';

const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
</React.StrictMode>,
);
Loading

0 comments on commit f8ea7d8

Please sign in to comment.