Swiftlint unused_import rule does not work - swift

I am using swiftlint for my project with SPM
I want to use unused_imports rule like this:
...
analyzer_rules:
- unused_import
...
But it does not find any violations, even thought they are in the project
I have also tried turn it on in the opt-in-rules section
Do you have any ideas, why this could happened?
I am running swiftlint lint --autocorrect

I found the solution
You need to build your project (or workspace) using xcodebuild tool and save the build logs
Then you may use it to run swiftLint analyze
I created this makefile script to do so:
# Run swiftlint analyze
lint-analyze:
make clean
xcodebuild \
-project <YOUR_PROJECT>.xcodeproj \
-scheme <YOUR_SCHEME> \
-destination 'platform=iOS Simulator,name=iPhone 13 Pro Max,OS=15.5' \
> xcodebuild.log
swiftlint analyze --fix --compiler-log-path xcodebuild.log --quiet
swiftlint lint --fix --format --quiet

Related

Swiftlint unable to open configuration file

I installed swiftlint through brew
brew install swiftlint
verified successfull installation through
swiftlint --version
0.50.1
Added script to project
export PATH="$PATH:/opt/homebrew/bin"
if which swiftlint >/dev/null; then
echo "SwiftLint started"
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
Also i have:
root project:
-> .swiftlint.yml
When i'm trying to build project I'm getting
Tried also
swiftlint lint --config project/.swiftlint.yml
Update:
After several mac restarts somehow after time it is fixed
Update: After several mac restarts somehow after time it is fixed

Travis fails after renaming a swift class

I was doing some refactoring on a Xcode Swift project. We had a spelling mistake in the name of a class which I corrected, both in the name of the class and in its declaration. Of course I changed every occurence as well.
The iOS projects builds and runs fine on my machine, but it does not on Travis. When I take a look into the travis logs I can see that the old file name is still in the build path – of course then it has to fail cause it won't be able to find that file.
Here's the .travis.yml
language: objective-c
osx_image: xcode9.2
before_install:
- gem install cocoapods
- pod setup
- pod install
script:
- export LC_ALL=en_US.UTF-8
- xcodebuild clean -project DQ-iOS-App.xcodeproj \
-scheme DQ-iOS-App CODE_SIGNING_REQUIRED=NO
- xcodebuild -verbose -workspace "DQ-iOS-App.xcworkspace" \
-scheme "DQ-iOS-App" -destination "platform=iOS Simulator,name=iPhone 8,\
OS=11.2" CODE_SIGNING_REQUIRED=NO
What am I missing here?
You can try to delete derrived data:
rm -rf ~/Library/Developer/Xcode/DerivedData

Swift project on GitHub travis-ci check always fail?

I don't know how to edit my .travis.yml. Every time travis-ci check fail, I am almost crazy!
This is my travis-ci link: https://travis-ci.org/liman123/DebugMan
This is my .travis.yml, is there anything wrong? Thanks!
osx_image: xcode8.3
language: objective-c
script:
- set -o pipefail && xcodebuild test -enableCodeCoverage YES -workspace
DebugMan.xcworkspace -scheme DebugMan -sdk iphonesimulator -destination
'platform=iOS Simulator,name=iPhone 6,OS=latest' ONLY_ACTIVE_ARCH=NO |
xcpretty
- pod lib lint
language: objective-c
script:
- xctool -project example.xcodeproj -scheme exampleTests build test -sdk
iphonesimulator GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES
GCC_GENERATE_TEST_COVERAGE_FILES=YES
after_success:
- bash <(curl -s https://codecov.io/bash)
Wrap your first script command in double quotes:
"set pipefail ... | xcpretty"

Use ant to create .ipa file

I want to clean, build and create .ipa file using an ant script. Also I need to set the application icon. I searched the web but couldn't find a solution. And i prefer to run the ant through the terminal.
Try searching for Ant + XCodeBuild. There should be plenty examples out there that give you a general idea how you can script an XCode build from ANT.
Key is the terminal xcodebuild command and you can only do this with Ant if you run your build on a Mac.
You can create a script.sh instead a Ant with this:
#!/bin/sh
cd {PROJECT_BUILDDIR}
xcodebuild -sdk iphoneos5.1 -configuration Release "ARCHS=armv6 armv7" clean build
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${PROJECT_BUILDDIR}/${PROJECT_NAME}.app" -o "${BUILD_HISTORY_DIR}/${APPLICATION_NAME}.ipa" --sign "${DEVELOPER_NAME}" --embed "${PROVISONING_PROFILE}"
And for start this, open Terminal and write:
sudo bash script.sh
This is is not tested, maybe exist a some small errors
For some tips

command-line library build fails with linker error

I am getting a library not found error building GraphViz current release (June 7 2012) with Xcode 4.3 using a script. I may have made mistakes updating build scripts from other people's successful recipes for the new location of Xcode4.3 and the developer tools in the Applications folder.
ld: library not found for -lcrt1.10.6.o
(doing this from memory so exact number on the CRT lib may be wrong)
Am also a little lost also how I would incorporate this into an Xcode build in the IDE. I am a very experienced programmer but having trouble finding my way around Xcode 4 at times. (Decades of Visual Studio et al).
I have copied the instructions from this earlier question and adapted
#!/bin/sh
# For iPhoneOS, see http://clang.llvm.org/ for options
export DEV_iOS=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
# was /Developer/Platforms/iPhoneOS.platform/Developer
export SDK_iOS=${DEV_iOS}/SDKs/iPhoneOS5.1.sdk
export COMPILER_iOS=${DEV_iOS}/usr/bin
export CC=${COMPILER_iOS}/clang
export CXX=${COMPILER_iOS}/clang++
export LDFLAGS="-arch armv7 -pipe -Os -gdwarf-2 -mthumb -isysroot ${SDK_iOS}"
export CFLAGS="${LDFLAGS}"
export OBJCFLAGS="${LDFLAGS}"
export CXXFLAGS="${LDFLAGS} -fvisibility-inlines-hidden"
export LD=${COMPILER_iOS}/ld
export CPP=${COMPILER_iOS}/clang
export AR=${COMPILER_iOS}/ar
export AS=${COMPILER_iOS}/as
export NM=${COMPILER_iOS}/nm
export CXXCPP="${COMPILER_iOS}/clang++"
export OBJC=${COMPILER_iOS}/clang
export RANLIB=${COMPILER_iOS}/ranlib
./configure \
--build=arm-apple-darwin11 \
--host=arm-apple-darwin11 \
--disable-dependency-tracking \
--enable-shared=no \
--enable-static=yes \
--enable-ltdl=no \
--enable-swig=no \
--enable-tcl=no \
--srcdir=${GVROOT} \
--with-codegens=no \
--with-cgraph=no \
--with-graph=yes \
--with-expat=no \
--with-fontconfig=no \
--with-freetype2=no \
--with-ipsepcola=yes \
--with-libgd=no \
--with-quartz=yes \
--with-visio=yes \
--with-x=no
The compiler normally uses crt1.o combined with crt[i/n].o and crt[begin/end].o to support the constructors and destructors (functions called before and after main and exit).
This error could be caused by this missing library file for the specific deployment target.
First, do some investigation, like:
list all your deployment targets:
ls -la /Developer/SDKs
and find which crt1 libraries do you have for which environment
find /Developer/SDKs -name crt1\*
You could see something like:
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/crt1.10.5.o
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/crt1.o
/Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.10.5.o
/Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.10.6.o
/Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.o
So as you can see, crt1.10.6.o is missing for MacOSX10.5.
Solution 1:
You can solve that by creating the link to the missing file pointed to the other environment, or you could change your deployment target.
E.g.
ln -s /Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.10.6.o /Developer/SDKs/MacOSX10.5.sdk/usr/lib/
Also this could be caused, that you have different gcc installed in your system. See:
which gcc;
xcrun -find gcc;
brew list | grep gcc; brew list gcc47
Solution 2
So when you're compiling using make, you can actually specify the right compiler by CC variable. E.g.
CC=/path/to/gcc-3.4 make
Solution 3
What you can also try is specifying the right target deployment environment variable for gcc, by executing the following lines:
export MACOSX_DEPLOYMENT_TARGET=10.5
export C_INCLUDE_PATH=/Developer/SDKs/MacOSX10.5.sdk/usr/include
export LIBRARY_PATH=/Developer/SDKs/MacOSX10.5.sdk/usr/lib
If this works, then you can add above lines to your shell profile (~/.profile) to make the change permanent.
How to test
Create the example conftest.c file with the following code:
#ifdef __GNUC__
yes;
#endif
And try to compile it via:
gcc conftest.c
cc conftest.c
cc conftest.cc conftest.c
Troubleshooting
To see which exactly what file is missing, try to debug it using dtruss, e.g.:
sudo dtruss -f gcc conftest.c 2>/dev/stdout | grep crt
You should see something like:
12426/0xb4e3b: stat64("/Developer/usr/lib/gcc/i686-apple-darwin10/4.2.1/crt1.10.6.o\0", 0x7FFF5FBFE780, 0xB) = -1 Err#2
So once you found the missing file, then you can follow by the first solution by linking the missing file from existing location (e.g. locate crt1.10.6.o). If you will have other missing symbols, then try another file (check the architecture before by: file `locate crt1.10.6.o`).
E.g.
sudo ln -s /Applications/Xcode.app/Contents/Developer//Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib/crt1.10.6.o /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/crt1.10.6.o
sudo ln -s /Applications/Xcode.app/Contents/Developer//Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib/crt1.10.6.o /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/x86_64/crt1.10.6.o
Related
Error in xcode project: ld: library not found for -lcrt1.10.6.o
If I remember correctly this is what fixed the library not found problem.
CFLAGS="$(OTHER_CFLAGS) -miphoneos-version-min=5.0"
LDFLAGS="$(OTHER_LDFLAGS) --miphoneos-version-min=5.0"
To link this to Xcode, under Build Settings then Header and Library search paths you need to add the paths to the built versions of the library and the header.
You can add the build script as part of your Xcode project, but I haven't had success with this, plus you should only need to build it once per version, so putting the time into anything other than a build script doesn't have much return.
If you decide to put the script in your project anyway (good luck!), then go to the build phases tab, add a build phase of type "Run Script" and paste your script there.